Mail Archives: djgpp-workers/1998/10/19/04:23:27
On Sat, 17 Oct 1998 Kbwms AT aol DOT com wrote:
> I am trying to use GNU sed to add a newline to the end of each line
> in a file. Any ideas?
Since every line already has a newline, I gather you want to insert an
empty line between every two lines, right?
If so then try this:
----------------- begin script.sed ------------------
a\
------------------ end script.sed -------------------
(Note the extra empty line at the end!)
Now type "sed -f script.sed file ..." and it should do what you want.
> This raises a larger question: what are the special-character escape
> sequences in GNU sed for tab, backspace, form feed, and newline?
None :-(. Sed doesn't support any non-printable characters. \n is
supported for the newline, but *only* for regular expressions that
match the pattern space, which means you need to use the N command or
its ilk to get this to work; and \n is NOT supported in the
replacement part of the `s' command. In other words, the following
script will work:
N
s/\n/^/
(it will remove all newlines and rerplace them with a `^'), but this
one will NOT:
N
s/\n/\n\n/
This non-support of escape sequences is not specific for GNU Sed,
that's how Posix specifies the standard Sed behavior.
A Unixy shell can sometimes be used to work around this, since the
shell would translate a \t to a literal TAB *before* it passes the
command line to Sed.
> Also, the binary archive sed302b.zip provides two executables, sed and
> gsed. What is gsed?
They use different implementations of the regexp library and have
different runtime speed. This is further explained in the file
gnu/sed-3.02/djgpp/README.djgpp.
(In general, I usually make a point of telling everything that isn't
self-evident or otherwise described in the usual docs in a
DJGPP-specific README file and include that file in the binary
distribution.)
- Raw text -