Home » Questions » Computers [ Ask a new question ]

Show only odd lines with cat

Show only odd lines with cat

HI,

Asked by: Guest | Views: 230
Total answers/comments: 4
Guest [Entry]

"Use sed:

sed -n 1~2p filename"
Guest [Entry]

"A simple search in Google shows this link: http://bash.cyberciti.biz/academic/write-odd-even-line-file/

You only need to tweak it a little bit.

My 2 cents."
Guest [Entry]

"Haven't tested this (doesn't seem to work on Mac OS X), but GNU sed supports first~step as an address selection, so for example:

sed -n 1~2p file

would start at the first line and print every other line after that."
Guest [Entry]

"It's really as simple as sed 'n;d' filename...
Or if you don't want to rely on en external command :
while read; do echo $REPLY; read; done < filename"