[SunHELP] sed, newline handling
James Lockwood
james at foonly.com
Wed Feb 12 16:16:27 CST 2003
On Wed, 12 Feb 2003, Markham, Richard wrote:
> Rich this is great. One final kicker, if you don't mind =).
...
> expected output:
> This,is,a,test
> This,is,a,test
> ...
One of many, many ways:
gosset:~ > cat thisisatest
This
is
a
test
and
this
gosset:~ > cat thisisatest |(awk '{ if ($1) { printf "%s,",$1 } else print }'; echo) |sed 's/,$//g'
This,is,a,test
and,this
This could also easily be done in perl, or in Bourne/Korn shell. I just
tend to think in awk. The sed statement strips off the trailing comma,
which is easier to do there than to avoid generating it in the first
place.
-James
More information about the SunHELP
mailing list