Hi,
Given the input file of three lines:
line 1
line 2
line 3
and the sed script
s/\</\
/g
s/^/hello/
which inserts a newline in front of every word and then prepends the
word "hello" to the beginning of the pattern space.
The following happens:
$ sed -f script.sed input.txt
hello
hello
hello
I was expecting to get
hello
line
1
hello
line
2
hello
line
3
This is a bit surprising since running only the first sed expression
gives (as expected)
line
1
line
2
line
3
The question is, why does the "line N" data disappear when inserting a
word at the start of the pattern space here?
I'm also noticing that this does not happen if a space (for instance)
precedes the escaped newline in the first expression:
s/\</ \
/g
s/^/hello/
This is using sed in the base system on OpenBSD 6.1-stable (amd64).
Cheers,
--
Andreas Kusalananda Kähäri,
National Bioinformatics Infrastructure Sweden (NBIS),
Uppsala University, Sweden.
No comments:
Post a Comment