Quick Answer: How Do You Display the Nth Line in Linux?
Contents

How do I print the nth line in Linux?

M~N with “p” command prints every Nth line starting from line M. For example, 3~2p prints every 2nd line starting from 3rd line as shown below.

How do you read the nth line in Unix?

N is the line number that you want. For example, tail -n+7 input. txt | head -1 will print the 7th line of the file.
…

  1. tail -n+N | head -1 : 3.7 sec.
  2. head -N | tail -1 : 4.6 sec.
  3. sed Nq;d : 18.8 sec.
Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest