本文翻译自: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 to check the data. 我需要转到第行来检查数据。 How do I do that? 我怎么做?
#1楼
参考:https://stackoom.com/question/a1mK/使用Unix中的Less来转到特定的行号
#2楼
For editing this is possible in nano via +n from command line, eg, 对于编辑,这可以在命令行的nano via +n进行,例如,
nano +16 file.txt
To open file.txt to line 16. 将file.txt打开到第16行。
#3楼
To open at a specific line straight from the command line, use: 要直接从命令行打开特定行,请使用:
less + filename
讯享网
If you want to see the line numbers too: 如果你想看到行号:
讯享网less + -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 on the 10th line of the terminal: 例如,这将在终端的第10行打开带有行的文件:
less + -j 10 filename
#4楼
From within less (in Linux): 从少到少(在Linux中):
讯享网
g and the line number to go forwardG 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; 单独使用,g和G将分别带到文件的第一行和最后一行; used with a number they are both equivalent. 与数字一起使用它们都是等价的。
An example; 一个例子; you want to go to line of a file, 你想去一个文件的第行,
press 'g' and after the colon type in the number 按'g'并在冒号后输入数字
Additionally you can type '-N' inside less to activate / deactivate the line numbers. 此外,您可以在less内键入'-N'来激活/停用行号。 You can as a matter of fact pass any command line switches from inside the program, such as -j or -N. 事实上,您可以从程序内部传递任何命令行开关,例如-j或-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: 注意:您可以在命令行中提供行号以减少(少于+数字-N),这比在程序内部执行要快得多:
less +12345 -N /var/log/hugelogfile
This will open a file displaying the line numbers and starting at line 12345 这将打开一个显示行号的文件,从第12345行开始
Source: man 1 less and built-in help in less (less 418) 资料来源:男子少1人,内置帮助少(少418人)
#5楼
With n being the line number: n为行号:
ng: Jump to line number n.ng:跳转到第n行。 Default is the start of the file. 默认值是文件的开头。nG: Jump to line number n.nG:跳转到第n行。 Default is the end of the file. 默认值是文件的结尾。
So to go to line number , you would type g . 因此,要转到第行,您需要输入g 。
Copy-pasted straight from Wikipedia . 直接从维基百科复制粘贴。
#6楼
You can use sed for this too - 你也可以使用sed -
讯享网sed -n ''p filename
This will print line number . 这将打印行号 。
If you want a range then you can do - 如果你想要一个范围那么你可以做 -
sed -n ','p filename
If you want from a particular line to the very end then - 如果你想从特定的线到最后那么 -
讯享网sed -n ',$'p filename
其他用法:
less 查看着一个文本,或者搜索到了目标,想修改,怎么办,这个时候,只要键盘输入"v"即可,会使用系统默认的编辑工具,马上就可以编辑啦。编辑完保存,会重新退回到less命令的使用。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/58052.html