vi / ex : resume on pattern fail
|
Original Message
|
Name: Anagram
Date: December 15, 2003 at 10:22:09 Pacific
Subject: vi / ex : resume on pattern fail OS: OSF/1 CPU/Ram: Alpha
|
Comment: Example situation: data.txt contains something like: abcdefghijklmno blahblah blahblah blah xxxxxxxxxxxxxxxx and then vi.script contains something like: :%s/abc/ABC/g :%s/HORK//g :%s/blahblah//g :wq
and is initiated via: vi data.txt < vi.script
This works just fine as long as the search pattern in all statements do exist. If one of them doesn't exist, then vi quits (returning 1) without processing any further commands. I want it to process all the commands, and if it runs into a pattern match that doesn't exist, I want it to just resume on the next line and keep going. So as in my example above, once if failed to find "HORK" in the file, I want vi to just continue on to look for "blahblah" and so forth instead of just quitting. Any clues?
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: nails
Date: December 15, 2003 at 11:26:25 Pacific
|
Reply: (edit)Hi: Using a Unix 'here' document seems to work, at least on my Solaris 7 box: vi data.txt <<MSG :%s/abc/ABC/g :%s/HORK//g :%s/blahblah//g :wq MSG
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Anagram
Date: December 15, 2003 at 12:09:16 Pacific
|
Reply: (edit)I thank you for your suggestion, nails. Alas, it made no difference on OSF/1. I did discover something interesting though: I briefly saw the stdout as the program was running, and I saw that vi printed the following notification: "press enter to continue". This is not seen when stdin is connect to a terminal; instead "Substitute pattern match failed" is what is seen. So I tried putting at the end of the non-matching line: ^V^M (key-escape,enter-key) and it successfully bypassed. But when I put it on lines that do have a match (and thus would not need the escaped enter key, the script fails again. Of course I can't just put escapes on only the problem lines because the point is I don't know which patterns will not be found.
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: Finnbarr P. Murphy
Date: December 16, 2003 at 12:14:44 Pacific
|
Reply: (edit)Many versions of vi/ex return this particular warning message. You probably would be better off (and safer) using the sed utility i.e. sed -f vi.sed data.txt > data.out where vi.sed contains s/abc/ABC/g; s/HORK//g; s/blahblah//g; - Finnbarr
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: