[BusyBox] busybox, sed, and zlib's configure script
Glenn McGrath
bug1 at optushome.com.au
Mon Sep 22 14:49:12 UTC 2003
On Mon, 22 Sep 2003 07:09:52 -0500
Rob Landley <rob at landley.net> wrote:
> $ echo -e "this\nis\na\ntest\n" | sed 's/\n/food/'
> this
> is
> a
> test
$ echo -e "this\nis\na\ntest\n" | sed 'N;s/\n/food/'
thisfoodis
afoodtest
sed reads one line into the pattern space and then run the sed commands
on them, however there are commands that force sed to read the next
line immediately.
e.g.
sed reads "this" into the pattern space and beggins to execute the
commands 'N;s/\n/food/'
The first command is 'N' which will read the next line of input i.e.
"is" and append it to the pattern space, so the pattern space now
contains "this\nis", the next command to be run is s/\n/food/, which
converts "this\nis" to "thisfoodis".
Its finished the last command so the process starts again, it reads the
next line from input i.e. "a" and by the same process converts "a\ntest"
to "afoodtest".
No more lines of input so its finished.
Another example
$ echo -e "this\nis\na\ntest\n" | sed 'N;N;N;s/\n/food/g'
thisfoodisfoodafoodtest
This reads the first line of "this" into the pattern space and starts
the sed commands, the 3 "N" sed commands tells it to read the next 3
lines and append them to the pattern space, so we now have
"this\nis\na\ntest" in the pattern space. "s/\n/food/g" substitutes the
3 '\n''s (g means global) with food, to give
"thisfoodisfoodafoodtestfood".
Glenn
More information about the busybox
mailing list