dattier(_at_)wwa(_dot_)com (David W. Tamkin) writes:
The problem was how to convert newlines to pipes without leaving a trailing
pipe at the end of the output (because of the closing newline in the input).
Andrew C. Feren suggested,
| Rather than using [sed's] y operator ... why not the following:
|
| sed '$q;s/$/|/'
|
| I can't think of a sed implementation that won't handle that.
[ snip ]
However, no sed implementation will get proper results from what Andrew re-
commended. Some don't grok semicolons and will exit with an error; that's
easily rectified,
sed '$ !s/$/|/'
I've seen a lot of sed implementations, but none that didn't
grok semicolons (thanks for the portability tip). 2 -e
switches would also fix my script.
but even at that it still preserves the newlines; it adds a pipe at the end
of every line except the last one, but the newlines remain after each pipe.
Oops. Good point.
You could do this,
variable=`sed '$ !s/$/|/' $file | tr -d \\12`
or this variation on Andrew's suggestion might work:
variable=`sed '$ !s/$/|\\/' $file`
I like the version without the pipeline.
--
-Andrew Feren (feren(_at_)ctron(_dot_)com)
Cabletron Systems Inc.
Durham, NH