On Monday 28 March 2011 08:39 PM, Rony wrote:
Hello,
I am trying to get a grip on sed and regular expressions. I found this site which looked nice but it appears to have mistakes in its examples.
For eg. on this page
http://docstore.mik.ua/orelly/unix/sedawk/ch02_03.htm
There is a file called 'list' and all commands are tested on this file. The file contents are:-
John Daggett, 341 King Road, Plymouth MA Alice Ford, 22 East Broadway, Richmond VA Orville Thomas, 11345 Oak Bridge Road, Tulsa OK Terry Kalkas, 402 Lans Road, Beaver Falls PA Eric Adams, 20 Post Road, Sudbury MA Hubert Sims, 328A Brook Road, Roanoke VA Amy Wilde, 334 Bayshore Pkwy, Mountain View CA Sal Carpenter, 73 6th Street, Boston MA
On the site this was a long single line. I broke it into each line for each name and now he substitution happens for every line.
They have created a script file called sedscr. I have put the text as asked by them which is pasted below
s/ MA/, Massachusetts/ s/ PA/, Pennsylvania/ s/ CA/, California/ s/ VA/, Virginia/ s/ OK/, Oklahoma/
However when I give this as input to the file called 'list', I get an error:- sed: file sedscr line 1: unknown option to `s'
The lines were put one below the other and now it works.
Thanks Rajeev and Binand.