substituting multiline string in sed
Hi Experts
I am facing a problem while using sed to replace a multiline string I have sed command stored in a file say command command file has the following content s/"Owner"/"Owner_T"/g s/"Contract Number"/"Contractnumtest"/g I want to replace "Contract Number" string with "Contractnumtest" the file with name say "file" which i have to edit is something like this "Owner" "Contract" "Contract Number" when i try to use sed to edit by doing this sed -f commands $file > file_outptut1.txt I am getting errors like sed: command garbled: s/"Contract I am using Solaris as OS. Is it possible to replace the multiline string using sed or sed commands have to be end in one line??? any solution/suggestion/pointers to solve this problem are welcome thanks in advance for helping |
You need to consult the sed&awk bible! Here:
http://www.unix.org.ua/orelly/unix/sedawk/ch06_01.htm Basically you should be able to use what's called the "hold space" to recognise and remember stuff from multiple lines. HTH |
Hi,
Your command file should look something like this: s/"Owner"/"Owner_T"/ /"Contract$/{ N s/"Contract\nNumber"/"Contractnumtest"/ } Nick_Battle gave good advice: All the info needed is in the Sed&Awk book. |
Hi.
I give you no extra magic, however, a rule that works for me is to remember that sed deals with single-lines unless you do some extra work. I could not get the URL that Nick posted to work ( page deleted ). If you can read Russian, perhaps some of the links at that top page might help. There are some other places to look. The web page http://sed.sourceforge.net/ has a number of links that may help. It is difficult to imagine a better reference than O'Reilly's sed and awk. I use the 2nd edition (page 107 ff for your circumstance); you might be able to pick up a used version someplace of either edition 1 or 2. I think sed is very useful in many situations, however, perl has probably taken over much of the new work for which sed had been used. Best wishes ... cheers, makyo |
All times are GMT -5. The time now is 04:57 PM. |