Smi*_*ile 2 command-line sed text-processing
sed -e 's/word1/word2/' -l 3 output > output2
Run Code Online (Sandbox Code Playgroud)
我正在测试这个命令。我预计每行 3 个字符。但是,它不起作用。output2与 具有相同的换行符output。我误解了换行吗?
简而言之......是的,你对换行有点误解;)
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
Run Code Online (Sandbox Code Playgroud)
因此,它仅适用于以下l命令:
l List out the current line in a ``visually unambiguous'' form.
l width
List out the current line in a ``visually unambiguous'' form,
breaking it at width characters. This is a GNU extension.
Run Code Online (Sandbox Code Playgroud)
如果你想每行输出三个字符,你可以使用这个:
sed -nl 4 's/word1/word2/;l' output > output2
Run Code Online (Sandbox Code Playgroud)
或者在 GNU 中sed:
sed -n 's/word1/word2/;l 4' output > output2
Run Code Online (Sandbox Code Playgroud)
请注意,如果实际上没有新行(行尾由$字符指示),则会附加一个尾随反斜杠(以转义换行符)。我们需要使用-n标志,因为l命令是用于查看而不是编辑,就像=命令一样,并且l在以请求的形式输出后,该行将正常显示,除非被-n.
通过在每三个字符后简单地打破文件,您可能会更像您真正想要的:
sed 's/word1/word2/; s/.../&\n/g' output > output2
Run Code Online (Sandbox Code Playgroud)
或者在 10 个字符后拆分:
sed -r 's/word1/word2/; s/.{10}/&\n/g' output > output2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
655 次 |
| 最近记录: |