Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.scriptThis 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?

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

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.

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

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |