Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

view a particular line of a file denoted by a number

Tags:

Okay, this is probably an evident thing but it escapes me, as in it could probably be done in a much simpler way that I'm not aware of, so far.. Say there's a "file" and I want to view only what's on line number "X" of that file, what would be the solution?

here's what i can think of:

head -X < file | tail -1    sed -n Xp < file 

is there anything else (or any other way) from the standard set of unix/gnu/linux text-tools/utils?

like image 951
XXL Avatar asked Mar 24 '11 12:03

XXL


People also ask

How do I view a specific line in Unix?

To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file. To look for the next occurrence after the first, either press n or press / again and then press Enter .


1 Answers

sed -n 'Xp' theFile, where X is your line number and theFile is your file.

like image 147
Jmoney38 Avatar answered Oct 27 '22 04:10

Jmoney38