Subject: Re: Single user mode: ed(1) or bust
To: Andrew Reilly <andrew-netbsd@areilly.bpc-users.org>
From: matthew sporleder <msporleder@gmail.com>
List: netbsd-users
Date: 05/16/2007 10:31:30
On 5/16/07, Andrew Reilly <andrew-netbsd@areilly.bpc-users.org> wrote:
> On Sat, May 05, 2007 at 08:58:49AM +0200, Lasse Hiller?e Petersen wrote:
> > Poor man's cat:
> > while read l ; do echo $l ; done <filein >fileout
> >
> > Now, what is a good candidate for poor man's ed?
>
> Not that I've ever tried to do this, but if your shell happened to be bash,
> then you could re-phrase your cat as:
>
> while read l; do echo ${l/pattern/substitute}; done <filein >fileout
>
> to give you something like a sed.  Unfortunately our shell can't do that, but
> you might be able to get by on a case-by-case process with a combination of
> line splitting and/or prefix/suffix substitution and counting (arithmetic
> expansion).
>


$ uname -a
NetBSD fester 3.1 NetBSD 3.1 (GENERIC) #0: Tue Oct 31 04:27:07 UTC
2006  builds@b0.netbsd.org:/home/builds/ab/netbsd-3-1-RELEASE/i386/200610302053Z-obj/home/builds/ab/netbsd-3-1-RELEASE/src/sys/arch/i386/compile/GENERIC
i386
$ echo $SHELL
/bin/ksh
$ cat test.txt

hey
how are you?
I am fine.
What did you do today?
I did a sound check.
-------

while read x;
do
if [ "$x" = "I am fine." ]
then
echo "not very well"
else
echo $x
fi
done < test.txt > test2.txt

--------
$
$ cat test2.txt

hey
how are you?
not very well
What did you do today?
I did a sound check.