shell脚本实现将文件中的几行输出合并成一行显示
现在有一个文件aa.txt ,其实现格式如下,而我想实现的结果是192.168.1.17 down
[root@localhost shell]# cat aa.txt
192.168.1.17down192.168.1.103open192.168.1.221open192.168.1.104down192.168.1.175down192.168.1.112open192.168.1.11down[root@localhost shell]# awk ‘{if (NR%2==0){print $0} else {printf”%s “,$0}}’ aa.txt
192.168.1.17 down192.168.1.103 open192.168.1.221 open192.168.1.104 down192.168.1.175 down192.168.1.112 open192.168.1.11 down或者
[root@localhost shell]# cat aa.txt | awk ‘{if(NR%2!=0)ORS=” “;else ORS=”\n”;print}’
192.168.1.17 down192.168.1.103 open192.168.1.221 open192.168.1.104 down192.168.1.175 down192.168.1.112 open192.168.1.11 down