我有一个包含以下行的文件:
[172.16.50.134] 62825
"/root/blz.txt" 62825
[172.16.50.133] 62933
"/home/Log/mail.log" 62933
"/home/Log/log.txt" 62933
[172.16.50.138] 67888
"/home/Log/test.txt" 67888
但我需要遵循以下格式:
[172.16.50.134] "/root/blz.txt"
[172.16.50.133] "/home/Log/mail.log"
[172.16.50.133] "/home/Log/log.txt"
[172.16.50.138] "/home/Log/test.txt"
如何使用Linux Shell脚本执行此操作? 谢谢。
答案 0 :(得分:0)
使用awk:
awk 'BEGIN{a=0;}/^\[/{printf "%s %s ",$1,$2; a=0; b=$1; c=$2; next;}{if(a==0) {print $1; a=1} else {print b,c,$1}}' filename