Hi All
I am having pipe seperated inputs like
Adam|PeteR|Josh|PEter
Nick|Rave|Simon|Paul
Steve|smith|PETER|Josh
Andrew|Daniel|StAlin|peter
Rick|PETer|ADam|RAVE
i want to repleace all the occurrence of peter (in any case pattern PeteR,PEter,PETER,peter,PETer) with Peter so that output looks like
Adam|Peter|Josh|Peter
Nick|Rave|Simon|Paul
Steve|smith|Peter|Josh
Andrew|Daniel|StAlin|Peter
Rick|Peter|ADam|RAVE
Please note that this is a part of the input and there are more cases of peter in the pipe separated file (like PETEr, PeTeR,petER etc) all needs to be replaced with Peter.
Thanks in advance.
Sudeep
birei
May 15, 2012, 2:40pm
2
Hi sudeep.id,
One way using perl:
$ cat infile
Adam|PeteR|Josh|PEter
Nick|Rave|Simon|Paul
Steve|smith|PETER|Josh
Andrew|Daniel|StAlin|peter
Rick|PETer|ADam|RAVE
$ perl -pe 's/(?i)\b(peter)\b/ucfirst lc $1/ge' infile
Adam|Peter|Josh|Peter
Nick|Rave|Simon|Paul
Steve|smith|Peter|Josh
Andrew|Daniel|StAlin|Peter
Rick|Peter|ADam|RAVE
Thanks
But the requirement has to be sufficed through a shell script or unix commands only. Can this be achieved via unix?
sed 's/[pP][eE][tT][eE][rR]/Peter/g' input > output
1 Like
Ohh... I missed this solution... How foolish of me... Thanks a lot
try this
awk 'BEGIN{IGNORECASE=1}/peter/{gsub(/peter/,"Peter");print}' filename