Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Going to a specific line number using Less in Unix

I have a file that has around million lines. I need to go to line number 320123 to check the data. How do I do that?

like image 376
Stole Avatar asked Dec 21 '11 08:12

Stole


People also ask

How do I go to a certain line number 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 .

How do I grep a specific line number in Unix?

The -n ( or --line-number ) option tells grep to show the line number of the lines containing a string that matches a pattern. When this option is used, grep prints the matches to standard output prefixed with the line number.

How do I go to a specific line number in Vim?

The Vim goto line number command One can use the G letter. For example, press [ESC] key and type 10G (Shift-g) goto line number 10.


2 Answers

With n being the line number:

  • ng: Jump to line number n. Default is the start of the file.
  • nG: Jump to line number n. Default is the end of the file.

So to go to line number 320123, you would type 320123g.

Copy-pasted straight from Wikipedia.

like image 116
n1r3 Avatar answered Sep 19 '22 02:09

n1r3


To open at a specific line straight from the command line, use:

less +320123 filename 

If you want to see the line numbers too:

less +320123 -N filename 

You can also choose to display a specific line of the file at a specific line of the terminal, for when you need a few lines of context. For example, this will open the file with line 320123 on the 10th line of the terminal:

less +320123 -j 10 filename 
like image 23
Ian Mackinnon Avatar answered Sep 19 '22 02:09

Ian Mackinnon