Press "Enter" to skip to content

Shell将换行符换成空格(sed)

Shell将换行符换成空格的办法,用sed和tr均可实现。

sed命令

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

tr命令

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

把tab换成换行符

cat country.txt | sed ‘s/\t/\n/g’

awk ‘BEGIN { OFS = "\n" } { $1=$1; print }’ input.txt > output.txt

tr ‘\t’ ‘\n’ < input.txt > output.txt

参考文章:
Convert a tab-delimited file to use newlines
sed命令替换换行符

Leave a Reply

Your email address will not be published. Required fields are marked *