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?
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.
g
, or you will jump one further line. –
Janettjanetta less 9581553g -N file.txt less: can't open '9581553g': No such file or directory
and also: less +G -N file.txt less: can't open '+G': No such file or directory
–
Beem less
not in shell. First you open the file less file.txt
and then enter your command 9581553g
–
Hallucination sed
or awk
where you could give specific line numbers as parameters. Thank you for clarifying. –
Beem 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
You can use sed
for this too -
sed -n '320123'p filename
This will print line number 320123.
If you want a range then you can do -
sed -n '320123,320150'p filename
If you want from a particular line to the very end then -
sed -n '320123,$'p filename
From within less (in Linux):
g and the line number to go forward
G and the line number to go backwards
Used alone, g and G will take you to the first and last line in a file respectively; used with a number they are both equivalent.
An example; you want to go to line 320123 of a file,
press 'g' and after the colon type in the number 320123
Additionally you can type '-N' inside less to activate / deactivate the line numbers. You can as a matter of fact pass any command line switches from inside the program, such as -j or -N.
NOTE: You can provide the line number in the command line to start less (less +number -N) which will be much faster than doing it from inside the program:
less +12345 -N /var/log/hugelogfile
This will open a file displaying the line numbers and starting at line 12345
Source: man 1 less and built-in help in less (less 418)
For editing this is possible in nano
via +n
from command line, e.g.,
nano +16 file.txt
To open file.txt
to line 16.
Just to add my 2 cents, in long files it is quicker to move to a given percentage, e.g typing 40%
moves to the 40-th
percentile of the length.
© 2022 - 2024 — McMap. All rights reserved.
more
? :-) – Crispiless
is more, but moremore
thanmore
is, somore
is lessless
, so use moreless
if you want lessmore
. – Janettjanetta