[ILUG] Re: sed question
Brendan Kehoe
brendan at zen.org
Thu Aug 14 15:15:59 IST 2008
> "first" is also on the first line of the input file. Apart from that it works
> fine, thanks. Does anyone know a one-liner sed/awk/perl to add a blank line to
> the start of a file? It seems to work fine if I add a blank line.
>
In a single step? Aside from
#!/bin/sh
echo > new-"$1"
cat "$1" >> new-"$1"
mv "$1" old-"$1"
mv new-"$1" "$1"
maybe for awk try either
awk '{if(NR==1) print ""; print;}'
awk 'BEGIN{print ""} {print;}'
or perl
perl -e 'print "\n"; while (<>) { print $_; }'
perl -e 'print "\n"; print while <>;'
? I'm sure there are great terse ways to do the same in each (and in
sed, which I've never obsessed on enough).
Hope this helps,
B
More information about the ILUG
mailing list