Personal tools
You are here: Home Docs Delete every other (n) line of a text file

Delete every other (n) line of a text file

by David Siedband last modified Mar 08, 2015 06:11 PM

Awk

awk 'NR % 2 == 0' sourcefile.txt > outputfile.txt

Sed

sed -n -e '1~2p' file # print odd lines
sed -n -e '0~2p' file # print even lines
sed -n -e '0~7p' file # every 7th line
Document Actions