当我跑步时\ls | xargs -I {} echo {} | sed 'N;s/\n/xxxxxxxxx/'
,我得到以下信息:
- Books aliasxxxxxxxxxA New Kind of Science
Computability-and-Logic.pdfxxxxxxxxxComputability-and-Logic_k2opt.pdf
Hein J. L. - Prolog Experiments in Discrete Mathematics, Logic, and Computability (2005).pdfxxxxxxxxxHein J. L. - Prolog Experiments in Discrete Mathematics, Logic, and Computability (2005)_k2opt.pdf
How Automated Recommendations Affect the Playlist Creation Behavior of Users.pdfxxxxxxxxxHow Automated Recommendations Affect the Playlist Creation Behavior of Users_k2opt.pdf
Lumanote- A Real-Time Interactive Music Composition Assistant.pdfxxxxxxxxxgeMsearch- Personalized Explorative Music Search.pdf
research_report_dc_02.pdfxxxxxxxxxresearch_report_dc_02_k2opt.pdf
thebookofshaders.pdfxxxxxxxxxthebookofshaders_k2opt.pdf
我不明白为什么输出不是这个:
- Books aliasxxxxxxxxxA New Kind of SciencexxxxxxxxxComputability-and-Logic.pdfxxxxxxxxxComputability-and-Logic_k2opt.pdfxxxxxxxxxHein J. L. - Prolog Experiments in Discrete Mathematics, Logic, and Computability (2005).pdfxxxxxxxxxHein J. L. - Prolog Experiments in Discrete Mathematics, Logic, and Computability (2005)_k2opt.pdfxxxxxxxxxHow Automated Recommendations Affect the Playlist Creation Behavior of Users.pdfxxxxxxxxxHow Automated Recommendations Affect the Playlist Creation Behavior of Users_k2opt.pdf
$ seq 10 | sed 'N;s/\n/+/'
1+2
3+4
5+6
7+8
9+10
N
在模式空间中添加下一行,然后使用将该s
两行连接起来+
,然后sed
打印该行,并为下一行输入重复脚本(其中第3和第4行用+
...等连接)。
你需要
$ seq 10 | sed 'N;N;N;N;N;N;N;N;N;s/\n/+/g'
1+2+3+4+5+6+7+8+9+10
或在您的sed脚本中使用循环来联接所有行:
$ seq 10 | sed -e :1 -e '$!N;s/\n/+/;t1'
1+2+3+4+5+6+7+8+9+10
请注意,它会将整个输入插入到模式空间中,无法很好地扩展到大文件。
要使用一个字符分隔符连接行,可以使用paste
:
$ seq 10 | paste -sd + -
1+2+3+4+5+6+7+8+9+10
对于不将整个输入加载到内存中的多字符分隔符:
$ seq 10 | awk -v sep=-+- -vORS= 'NR>1 {print sep}; 1; END {if (NR) print RS}'
1-+-2-+-3-+-4-+-5-+-6-+-7-+-8-+-9-+-10
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句