如何使用sed
,awk
或bash
最简洁地将文件格式A转换为B?
A
1
blabla
2
another blabla
... (more omitted)
10
yet another blabla
...
100
final blabla
乙
1 blabla
2 another blabla
...
10 yet another blabla
...
100 final blabla
答案 0 :(得分:1)
有很多不同的方式,这里有一个使用paste
$ cat ip.txt
1
blabla
2
another blabla
10
yet another blabla
100
final blabla
$ paste - - < ip.txt
1 blabla
2 another blabla
10 yet another blabla
100 final blabla
有关更多方法,请参阅How to process a multi column text file to get another multi column text file?
答案 1 :(得分:0)
在一个bash行中:
while read line1; do if read line2; then echo "$line1" "$line2"; fi; done < file.txt
答案 2 :(得分:0)
在Bash
中使用$ pr -2 -a -s\ -t foo2
1 blabla
2 another blabla
10 yet another blabla
100 final blabla
:
$job['description'] = ltrim($job['description']);
$job['description'] = preg_replace('/^\s+/S', " ", $job['description']);