I want to parse a file containing special characters, below is a sample content of file
content of file :
Serial_no:1$$@#first_name:Rahane$$@last_name:Ajiyenke@@#profession:cricketer!@#*&^
Serial_no:1$$@#first_name:Rahane$$@last_name:Ajiyenke@@#profession:cricketer!@#*&^
first_name:suni$%&*Age:25$#@*last_name:chetri%$*&#profession:Soccer$%^#serial_no:3#@@@
first_name:suni$%&*Age:25$#@*last_name:chetri%$*&#profession:Soccer$%^#serial_no:4@$#$
can you please suggest how to search special character in a file
below is own snippet of code , I am trying to impliment to extract the index of the special character occurance in each line.However it does not work.
awk '{print index($0,"*[\$]\2[\@\]*")}'
Please tell me how to impliment this.
Thanks
What does make "special characters" so special? Never heard of "special characters".....
what's the desired out based on a sample provided?
I think he means punctuation characters but one can guess ...
awk ' { print $0 FS gsub(/[:punct:]/,"") } ' inputfile
The awk index()
function's 2nd argument is a fixed string; not an extended regular expression (as you would use in sub()
or gsub()
). And, even it were an ERE, your ERE syntax is way off. Making a very wild guess that you're looking for the first occurrence of the string $$@
on each line, try:
awk '{print index($0, "$$@")}' file
which, with your sample input, produces the output:
12
12
0
0
since the 1st occurrence of $$@
starts at character 12 in the first two lines of your input, but does not appear at appear all in the last two lines.
If this isn't what you want, please tell us in English what you are trying to do AND show us the output (in CODE tags) that you are trying to produce from the input you have shown us.