Your Question: How Do You Print the Nth Line in Unix?
Contents How Do I Print the Nth Line in Linux? Below Are Three Great Ways to Get the Nth Line of a File in Linux. Head / Tail. Simply Using the Combination of...
Contents
How do I print the nth line in Linux?
Below are three great ways to get the nth line of a file in Linux.
- head / tail. Simply using the combination of the head and tail commands is probably the easiest approach. …
- sed. There are a couple of nice ways to do this with sed . …
- awk. awk has a built in variable NR that keeps track of file/stream row numbers.
Must Read
How do you find the nth line in Unix?
5 Answers. Sure. If the file is long and you’re only interested in one line, use sed to print the desired line and quit, or tail to remove the previous lines and head to extract the first line of the result. (Note that tail -n +$n skips n-1 lines, i.e. its output starts with the nth line.)