我有一個看起來像這樣的列表:將某些行前面的行
sharename:shareX
comment:commentX
sharename:shareY
comment:commentY
sharename:shareZ
comment:commentZ
等等...
而且我這是怎麼想的名單看起來像:
shareX;commentX
shareY;commentY
shareZ;commentZ
如何在bash中完成該操作?
我有一個看起來像這樣的列表:將某些行前面的行
sharename:shareX
comment:commentX
sharename:shareY
comment:commentY
sharename:shareZ
comment:commentZ
等等...
而且我這是怎麼想的名單看起來像:
shareX;commentX
shareY;commentY
shareZ;commentZ
如何在bash中完成該操作?
一個班輪:
odd=0; for i in `cat list | cut -d":" -f2`; do if [ $odd -eq 0 ]; then echo -ne $i; odd=1; else echo $i; odd=0; fi; done
格式:
odd=0;
for i in `cat list | cut -d":" -f2`;
do
if [ $odd -eq 0 ];
then
echo -ne $i";";
odd=1;
else
echo $i;
odd=0;
fi;
done
純擊:
IFS=':'
while read a b; read c d; do # read 2 lines
echo -e "$b:$d"
done < "$infile"
不錯。從我+1。 – 2012-04-27 13:14:31
未經測試,桑達部分可能是錯誤的
paste -d ';' - - < filename | sed -r 's/(^|;)[^:]:/\1/g'
這可能適合你:
sed '$!N;s/[^:]*:\([^\n]*\)\n[^:]*:/\1;/' file
shareX;commentX
shareY;commentY
shareZ;commentZ
謝謝!也必須改變IFS,因爲有些評論在其中有空間和逗號。 – 2012-04-27 12:45:05