说明:过滤换行符确实有点吭,不是那么好弄。处理文本时需要将换行符替换为空格,若使用sed命令会比较麻烦,而使用tr命令非常方便。
![](https://i-blog.csdnimg.cn/blog_migrate/d5309e7944456a579c633ffc8f77a3c7.png)
输入文本(country.txt)
China
America
France
German
sed命令
cat country.txt | sed ':label;N;s/\n/ /;b label'
tr命令
cat country.txt | tr "\n" " "
两个命令输出一致,但是sed命令的输出结尾有换行符,而tr命令的输出结尾没有换行符
China America France German
参考:
http://bbs.chinaunix.net/thread-1189438-1-1.html
http://blog.itpub.net/27042095/viewspace-1092874/
https://www.jianshu.com/p/82c7a18c1120(以上内容转自此篇文章)
https://www.cnblogs.com/leaven/archive/2011/01/11/1933105.html
https://www.cnblogs.com/vincent4code/p/5951258.html
http://blog.csdn.net/guoyajie1990/article/details/73692526
http://blog.csdn.net/robertsong2004/article/details/38588547
https://www.zhihu.com/question/31590312