2013-12-23 59 views
0

TXT文件:如何使用獲得指定的行並將它添加到前面的行

ruby193-rubygem-sqlite3-doc.noarch 1.3.6-1.el6  rhel-x86_64-server-6-ost-3 
ruby193-rubygem-test_declarative.noarch 
            0.0.5-3.el6  rhel-x86_64-server-6-ost-3 
ruby193-rubygem-test_declarative-doc.noarch 
            0.0.5-3.el6  rhel-x86_64-server-6-ost-3 
ruby193-rubygem-therubyracer.x86_64 0.11.0-0.5.beta5.el6 
                 rhel-x86_64-server-6-ost-3 
ruby193-rubygem-therubyracer-doc.noarch 
            0.11.0-0.5.beta5.el6 
                 rhel-x86_64-server-6-ost-3 
ruby193-rubygem-thin.x86_64   1.3.1-8.el6ost rhel-x86_64-server-6-ost-3 
ruby193-rubygem-thin-doc.x86_64  1.3.1-8.el6ost rhel-x86_64-server-6-ost-3 
ruby193-rubygem-thor.noarch   0.15.4-1.el6  rhel-x86_64-server-6-ost-3 
ruby193-rubygem-thor-doc.noarch  0.15.4-1.el6  rhel-x86_64-server-6-ost-3 
ruby193-rubygem-tilt.noarch   1.3.3-9.el6  rhel-x86_64-server-6-ost-3 

我想追加「版本」以前行

例如:從 :

ruby193-rubygem-therubyracer-doc.noarch 
            0.11.0-0.5.beta5.el6 
                 rhel-x86_64-server-6-ost-3 

到:

ruby193-rubygem-therubyracer-doc.noarch 0.11.0-0.5.beta5.el6 rhel-x86_64-server-6-ost-3 

並保留默認值。

回答

0
$ gawk -v RS='\0' '{ gsub ("\n\\s+", " "); print }' inputfile | column -t 

您是否需要任何意見?

0
awk 'NF<3 {ORS=""; i+=NF} NF==3||i==3 {ORS="\n";i=0}1' input | column -t 
0

另一個變化:

awk '{$1=$1} /^ruby/{if(s)print s;s=$0;next} {s=s" "$0} END {print s}' file 

{$1=$1}用於清潔多餘的空格。

0

使用xargs的

xargs -n3 < file 
相關問題