如果我已将命令的结果通过管道传送到less,然后决定将内容保存到文件中,这可能吗?
我试过a在缓冲区的末尾设置一个标记,然后返回到顶部并使用|avi将整个内容发送到vi,但这不起作用。
Red*_*ick 123
在我的系统上,man less说
s filename
Save the input to a file. This only works if the input is a
pipe, not an ordinary file.
Run Code Online (Sandbox Code Playgroud)
为我工作!
小智 32
接受的答案在 Mac 上不起作用——正如@benroth 所说,按下s只是向下移动——但你可以使用不同的方法。
在less --help:
|Xcommand Pipe file between current pos & mark X to shell command.
Run Code Online (Sandbox Code Playgroud)
和
A mark is any upper-case or lower-case letter.
Certain marks are predefined:
^ means beginning of the file
$ means end of the file
Run Code Online (Sandbox Code Playgroud)
因此,如果您转到缓冲区 ( <)的顶部,然后:
|$cat > /tmp/foo.txt
Run Code Online (Sandbox Code Playgroud)
缓冲区的内容将被写出到/tmp/foo.txt.
小智 7
当你less打开,你可以保存完整的输出到文件中。比如vim,less 支持命令。
只需键入 key s,然后less会询问您要保存内容的文件的名称,只需键入文件名,然后键入Enter.
干杯
| 归档时间: |
|
| 查看次数: |
29044 次 |
| 最近记录: |