ed & redirected input

Steven M. List itkin at mrspoc.UUCP
Wed May 17 05:58:20 AEST 1989


In article <9700003 at osiris.cso.uiuc.edu> funk at osiris.cso.uiuc.edu writes:
> ed $i <<honker
> 1,\$ s/pat1/$site/g
> 1,\$ s/pat2/$cmty/g
> w
> q
> 
> 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, (and it complains about not having seen a "w"), with the effect that the
> file is NOT updated, even though it should have worked for the occurrences
> of pat2.  All other files are correctly updated, as they contain occurrences
> of both pat1 and pat2.  If I do it by hand, ed of course complains about the
> no match, but still processes any subsequent commands.
> 
I'm not sure if this is EXACTLY your problem, but I've run into this before.
The problem is that ED doesn't like "1,$s/x/y/" if there are no "x" strings
in the file.  The cleaner way to do this, when you want to perform these
operations across the whole file is to use the global command:

ed $i <<honker
1,\$ g/pat1/s//$site/g
1,\$ g/pat2/s//$cmty/g
w
q
honker

Since the global command causes (1) all lines that satisfy the search
criteria to be marked and then (2) all marked lines to be operated on,
this doesn't fail when there ARE no marked lines.
-- 
:  Steven List @ Transact Software, Inc. :^>~
:  Chairman, Unify User Group of Northern California
:  {apple,coherent,limbo,mips,pyramid,ubvax}!mrspoc!itkin
:  Voice: (415) 961-6112



More information about the Comp.unix.questions mailing list