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

原数据文件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 "\n" "|" < s.txt

4、vim

vim s.txt
:%s/\n/|/g

 

你可能感兴趣的:(将多行按分隔符"|"合成一行)