当我运行\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发布于 2018-08-10 15:07:44
发生这种情况是因为sed是逐行处理的。您必须像这样循环:sed -e ':again' -e 'N;s/\n/xxxxx/' -e 'tagain',或者更简单的方法是使用tr "\n" "xxxxx"
https://unix.stackexchange.com/questions/461826
复制相似问题