首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么这个命令只对其他行起作用?

为什么这个命令只对其他行起作用?
EN

Unix & Linux用户
提问于 2018-08-10 14:59:52
回答 1查看 184关注 0票数 -1

当我运行\ls | xargs -I {} echo {} | sed 'N;s/\n/xxxxxxxxx/'时,我得到了这样的信息:

代码语言:javascript
复制
- 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

我不明白为什么输出不是这样的:

代码语言:javascript
复制
- 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
EN

回答 1

Unix & Linux用户

发布于 2018-08-10 15:07:44

发生这种情况是因为sed是逐行处理的。您必须像这样循环:sed -e ':again' -e 'N;s/\n/xxxxx/' -e 'tagain',或者更简单的方法是使用tr "\n" "xxxxx"

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/461826

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档