美文网首页Linux命令Linux学习|Gentoo/Arch/FreeBSD技术文
tr与sed命令:将换行符替换为空格

tr与sed命令:将换行符替换为空格

作者: KiwenLau | 来源:发表于2015-06-24 21:55 被阅读14075次

处理文本时需要将换行符替换为空格,若使用sed命令会比较麻烦,而使用tr命令非常方便。

输入文本(country.txt)

China
America
France
German

sed命令(参考sed命令替换换行符)

cat country.txt | sed ':label;N;s/\n/ /;b label'

tr命令

cat country.txt | tr "\n" " "

两个命令输出一致,但是sed命令的输出结尾有换行符,而tr命令的输出结尾没有换行符

China America France German

版权声明
转载时请注明作者KiwenLau以及本文地址:http://kiwenlau.com/2015/06/23/tr-sed-newline/


相关文章

网友评论

    本文标题:tr与sed命令:将换行符替换为空格

    本文链接:https://www.haomeiwen.com/subject/gyteqttx.html