我想打印/回显或重定向以下行到某个文件中
phone: "3434343"
name: "jack"
phone: "9876735"
name: "john"
phone: "3434343"
name: "Mack"
...multiple emptylines ...
phone: "9876735"
name: "doe"
phone: "3434343"
name: "tack"
所需的输出行是:-
phone: "3434343" name: "jack"
phone: "9876735" name: "john"
...
下面是我写的工作
cat /tmp/sip_summary2.log | while read LINE;
do
echo $LINE | grep '^$' > /dev/null
if [ $? -eq 0 ]
then
echo " " >> /tmp/tempsip.log
else
printf "%s " "$LINE" >> /tmp/tempsip.log
fi
done
有没有更好或更清洁的替代方案?
最佳答案
awk
解决方案:
awk -v RS= '{$1=$1}1' inputfile
这里默认的
RS
更改为空白。 {$1=$1}
用于记录重建,1
用于打印记录。关于bash - 将多对线更改为单线?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42246959/