2

Want the comma's (,) replaced by the alphabet u between the first occurrence of y till the second occurrence of y. Given below is the sample input file.

100y00893225900,008932259,06,2013,NOKIA Q PHONE,TXS000000287356,PDF,Text,MEOB,1.4,00 00,DoD,07/07/2013,06/01/2013,06/30/2013,07/10/2024,trueyr=56734,d=199y
56734_199_0.pdf
100y00893225900,008932259,06,2013,SAMSUNG T PHONE,TXS000000287356,PDF,Text,MEOB,1.4,00 00,DoD,07/07/2013,06/01/2013,06/30/2013,07/10/2024,trueyr=56734,d=199y
56734_199_0.pdf      
100y00893225900,008932259,06,2013,APPLE S PHONE,TXS000000287356,PDF,Text,MEOB,1.4,00 00,DoD,07/07/2013,06/01/2013,06/30/2013,07/10/2024,trueyr=56734,d=199y
56734_199_0.pdf
~
~
~

Actually speaking each line has 3 "y" occurrences.

Desired Output:

100y00893225900u008932259u06u2013uNOKIA Q PHONEuTXS000000287356uPDFuTextuMEOBu1.4u00 00uDoDu07/07/2013u06/01/2013u06/30/2013u07/10/2024utrueyr=56734,d=199y
56734_199_0.pdf
100y00893225900u008932259u06u2013uSAMSUNG T PHONEuTXS000000287356uPDFuTextuMEOBu1.4u00 00uDoDu07/07/2013u06/01/2013u06/30/2013u07/10/2024utrueyr=56734,d=199y
56734_199_0.pdf
100y00893225900u008932259u06u2013uAPPLE S PHONEuTXS000000287356uPDFuTextuMEOBu1.4u00 00uDoDu07/07/2013u06/01/2013u06/30/2013u07/10/2024utrueyr=56734,d=199y
56734_199_0.pdf
~
~
~
7
awk -Fy -v OFS=y '{gsub(",","u",$2); print}' file
2
  • :Thanks! Works Perfectly! Can please explain this? – Ram Feb 6 '14 at 16:04
  • This uses the character "y" as the field separator (-Fy). the text between the 1st and 2nd "y" is thus the 2nd field. Change the commas with the gsub command. Print out the modified line, using "y" as the output field separator (-v OFS=y) – glenn jackman Feb 6 '14 at 16:32
0

And here's a Perl one, only a little longer:

perl -Fy -ane 'do{$F[1]=~s/,/u/g; $,="y";} if /y/; print @F;' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.