[Techtalk] ed < file

Malcolm Tredinnick malcolm at commsecure.com.au
Wed Nov 13 20:09:44 EST 2002


On Wed, Nov 13, 2002 at 08:56:40AM +0100, Dan Richter wrote:
> I'm trying to use the "ed" command like this:
>   ed $filename <<EOF
>   1,$s/foo/bar/g
>   w
>   q
>   EOF
> The commands work when I type them one-by-one, but not when I execute them 
> as shown above. (I've tried ed -s and that didn't work either.) Can anyone 
> explain why?

The above command has the effect of passing lots of different arguments
to ed, no passing it stuff on stdin. You are doing the equivalent of

		ed foo 1,s/foo/bar/g ...

and the subsequent arguments are ignored.

What you want to do is:

(cat <<EOF; ) | ed filename
1,$s/foo/bar/g
w
q
EOF

or something equivalent (there are other ways to arrange the
parentheses, here document and pipe -- the above is just one that
springs to mind). This forces the stuff before the pipe to be presented
on stdin to the 'ed' command.

If you would like this explained further, sing out.

Cheers,
Malcolm

-- 
Atheism is a non-prophet organization.



More information about the Techtalk mailing list