bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sed bug, incorrect doc or me misunderstanding


From: Hans-Bernhard Broeker
Subject: Re: sed bug, incorrect doc or me misunderstanding
Date: 2 Nov 2001 14:03:20 GMT

Daniel Horchner <address@hidden> wrote:

> The following command
>   sed "s/\n/EOL/g" testfile
> should substitute all newline characters in testfile with the string
> EOL and send the output to stdout. However, sed seems to ignore the
> \n in REGEXP and doesn't replace anything.

The problem is that the newline characters from your input file never
end up where the regexp could see and match them, because sed splits
your input into individual lines your commands are applied to.  To
match a linebreak in the input file, you have the '$' operator:

~> echo '1\n2\n3' | sed 's/$/EOL/'
1EOL
2EOL
3EOL

Newlines can only ever be in the "input space" if you played around
with sed's 'a', 'i' or 'r' or hold-space commands, before.
-- 
Hans-Bernhard Broeker (address@hidden)
Even if all the snow were burnt, ashes would remain.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]