0

I know how to use head or tail to output a certain number of lines, but how do I output only a specific line number(s)?

Something like:

head --only-line=73 <file>

1 Answer 1

0

How do I output only a specific line number?

head -n LINE_NUMBER file.txt | tail -n + LINE_NUMBER

where LINE_NUMBER is which line number you want to print.

You can also use:

awk '{if(NR==LINE_NUMBER) print $0}' file.txt

Or

sed -n LINE_NUMBERp file.txt

Source: Write a bash script to print a particular line from a file - GeeksforGeeks


See Also:

1
  • I promise I did search! Must have been a long day... thanks for the detail. The head .. | tail .. does seem a bit memory intensive. Perhaps on a fundamental level this is how any process can read the file. Commented Nov 8, 2023 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .