At 19:27 22/06/00, Fergal Daly wrote:
>At 19:21 22/06/00, Lars Hecking wrote:
>>> I was going to post this under "Tip of the day", but then it came
>> to me that others might enjoy a little food for their brain cells :)
>>>> The task: delete every other line in a text file. Naturally, I'm looking
>> for a scriptable, small, and elegant solution. This probably excludes
>> Word macros ...
>>perl -ne 'print if $a; $a = not $a' filename
>>or if you want the odd line
>>perl -ne 'print if not $a; $a = not $a' filename
Sorry but I'd hate it if someone else posted these.
perl -ne 'print if ($. % 2)'
which works can be adjusted to print/skip every nth line.
Also, depending on whether you want to skip the first or second line
perl -ne '<>;print' filename
perl -ne 'print;<>' filename
Hmm... just tested those last 2 and they both print only the odds, what's
going on there?
I don't think this'll be beat
perl -pe '<>' filename
Finally if all this perl is just too much for you
cat -n filename | grep "^ *[0-9]*[[:space:]]" | sed 's/^
would be a ridiculous but Perl-free way around it,
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!