ed & redirected input
Guy Harris
guy at auspex.auspex.com
Wed May 17 03:52:04 AEST 1989
>It works like a champ EXCEPT if one of the files (say file2) does NOT contain
>an occurrence of pat1. Then ed proceeds to ignore everything else except the
>q,
Yup. That's deliberate. A command of the form "1,$s/pat1/pat2/g" fails
if it doesn't find at least one instance of "pat1"; if a command fails,
"ed" assumes that the script isn't finding what it expects to find, and
therefore blows the rest of the script off, under the assumption that
you may not get the results you expect from the script....
>I finally gave up and resorted to using sed into a temp file and moving the
>temp file back to the original file. But it still leaves me wondering
> HOWCUM????
See above.
If you want a "substitute" command of that sort that *doesn't* fail if
it doesn't find any instances of the pattern, try
g/pat1/s//pat2/g
rather than
1,$s/pat1/pat2/g
More information about the Comp.unix.questions
mailing list