Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unix command to read line from a file by passing line number

Tags:

I am looking for a unix command to get a single line by passing line number to a big file (with around 5 million records). For example to get 10th line, I want to do something like

command file-name 10

Is there any such command available? We can do this by looping through each record but that will be time consuming process.

like image 300
jgg Avatar asked Jul 20 '10 00:07

jgg


2 Answers

This forum entry suggests:

sed -n '52p' (file)

for printing the 52th line of a file.

like image 183
schnaader Avatar answered Jan 08 '23 15:01

schnaader


Going forward, There are a lot of ways to do it, and other related stuffs.

If you want multiple lines to be printed,

sed -n -e 'Np' -e 'Mp'

Where N and M are lines which will only be printed. Refer this 10 Awesome Examples for Viewing Huge Log Files in Unix

like image 39
thegeek Avatar answered Jan 08 '23 15:01

thegeek