将多行按分隔符"|"合成一行

原数据文件s.txt

api_test
account
info
4003
参数错误
0
1
1411895193
105
1

合并后数据格式

api_test|account|info|4003|参数错误|0|1|1411895193|105|1

方法介绍:

1、sed + xargs

sed 's/$/|/' s.txt | xargs

2、awk

awk 'BEGIN{FS=" ";ORS="|"}{for(i=1;i<=NF;i++) { print $i} }' s.txt

3、tr

tr "
" "|" < s.txt

4、vim

vim s.txt
:%s/
/|/g
原文地址:https://www.cnblogs.com/brookin/p/3999298.html