wbshrk
October 27, 2009, 10:33am
1
I am trying to write a find and replace script with AWK and I can't seem to get it to work. I need it to find this exact string *P*: and replace the P with a T or just replcare the whole thing with *T*:.
this is what I have tried
awk 'BEGIN {gsub(/\*P*:/,"\*T*:"); print}' ${INFILE} > ${INFILE}.out
Wbshrk
to replace exact string, you can try not using / /
awk '{gsub("*p*","")}1' file
zaxxon
October 27, 2009, 10:48am
3
awk '{gsub(/\*P\*:/,"\*T\*:"); print}' infile
Remove the BEGIN and escape the second * in the pattern and replacement too.
wbshrk
October 27, 2009, 10:54am
4
Does not work, just does nothing.
---------- Post updated at 09:54 AM ---------- Previous update was at 09:51 AM ----------
zaxxon:
awk '{gsub(/\*P\*:/,"\*T\*:"); print}' infile
Remove the BEGIN and escape the second * in the pattern and replacement too.
Get this message
awk: warning: escape sequence `\' treated as plain ` '
and then is sits and does nothing.
zaxxon
October 28, 2009, 1:30am
5
l> awk '{gsub(/*P*:/,"*T*:"); print}' infile
lala *P*T*:lala
If you have nawk on your system try using that. Or try that one:
sed 's/\*P\*:/\*T\*:/g' infile
lala *T*:lala
If still nothing of this works on your box, post a snippet of your input.