Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Simple' sed problem 3

Status
Not open for further replies.

dickiebird

Programmer
Feb 14, 2002
758
GB
Guys
I know that sed 's/.....RA...0/&K/g' < infile > outfile
will insert a K after position 11 in a record.
but I need to replace the 0 in position 11 with a K
How do I do that ?
TIA Dickie Bird (:)-)))
 
This is a bit of a hack, but the way I do this type of thing is - first determine a character which doesn't occur anywhere in the input file (in my example a closing square bracket) then change all occurrences of '..........0' to '..........0]' & then change all occurrences of '0]' to 'K'.

(Sorry but I did say it was a hack)

Chris
 
sed 's/\(.....RA...\)0/\1K/'< infile > outfile

or perhaps sed 's/0$/K/' < infile > outfile

 
Chris - the hack works fine - but you'll agree that Pavnell's solution is neat !
Thanks Guys, for your prompt responses. Dickie Bird (:)-)))
 
Certainly do - I always forget that you can refer to previous string values in sed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top