Unix Cat Starting from Line

What is the best way to output from a file starting from a specific line (big number like 70000). Something like:

cat --line=70000 <file>

5 Answers

Take a look at tail, more precisecly, it's --lines=+N switch:

tail --lines=+100 <file>
2

The most obvious way is tail. The syntax might be slightly different depending on what OS you are using:

tail -n +70000

If you can not get tail to work, you could use sed, but it might end up slower:

sed -pe '1,69999d'
1

You can use NR parameter with the awk command:

cat <file> | awk '{if (NR>=7000) print}'
1

If instead of a line number you need to start listing at the line containing a given $phrase, try the following.

more -1000 +/"$phrase" yourfilename | sed '1,4d'

The -1000 will continuously list text for up to 1000 lines; you can change this as needed. The sed command will chop off the first 4 lines of output, which were automatically inserted by more, containing a blank line, the message "... skipping", and the two lines preceding your intended starting line. I guess this may vary depending on your system.

Your Answer

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

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest