Monday, July 18, 2011
How to print a specific line in Shell
Posted on 2:27 PM by APC
In this post we will discuss how to print a specific line from a file. Suppose you have a file with 50000 line and you want to print just the 100th line. My favourite way to do so is by using a combination of tail and head command. Here is the commands that can be used for the mentioned purpose:
tail -n +100 filename | head -n1
Tail -n +100 gives all the lines starting from 100th line. Then we use head -n1 which gives the first line. A combination of bot gives the 100th line.
The example can be made generic by replacing 100 by your desired value.
Subscribe to:
Post Comments (Atom)


No Response to "How to print a specific line in Shell"
Leave A Reply