[clug] Two (perhaps simple) shell questions.
Mark Triggs
mark at dishevelled.net
Tue Aug 18 03:47:34 MDT 2009
Andrew Janke <a.janke at gmail.com> writes:
> 1) I had a need (really) to remove every second newline from a file
> the other day and all I could think of was this:
>
> $ awk 'ORS=NR%2?" ":"\n"' ...
>
> That is replace the newline with a space. Is there a "better way"?.
> tr came to mind but I didn't get far.
I can't resist the Perl one-liner:
perl -pe 'chomp if !($. % 2)' < myfile
Let the Perl golf begin :o)
--
Mark Triggs
<mark at dishevelled.net>
More information about the linux
mailing list