I want to delete the first 12 lines from a file, keep the next 12 lines and repeat this to the end of the file using a Linux command or shell-script.


Pipe it through perl -nle 'print if ((($.-1)/12)%2)'


Using the facilities of GNU awk

awk -v RS='([^\\n]*\n){12}' '!(FNR % 2){printf "%s", RT}' file

sed can choose ranges of lines, then delete them:

sed -i '1~24,+11d' file

Another awk variant:

awk '(NR-1)%24>11' file.txt > result.txt

use tail "reversed"

tail -n +5

prints everything but the first five lines.

head -n 5

prints the first five lines. So if you want to print lines 6 to 10:

cat yourfile | tail -n +5 | head -n 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.