写一个sed命令来提取单词

时间:2013-02-03 01:05:00

标签: shell sed

有一个我想要的文件

libqt4-dbus   
libqt4-network   
libqt4-script   
libqt4-test   
libqt4-xml   
libqtcore4   
libqt4-designer   
libqt4-opengl   
libqt4-svg   
libqtgui4 

如何编写sed命令,例如sed 's/ /' test

这是名为test

的文件

以下软件包具有未满足的依赖项:

  

libqt4-core:取决于:libqt4-dbus(= 4:4.8.2 + dfsg-10)但是   4:4.8.2 + dfsg-2将被安装                  取决于:libqt4-network(= 4:4.8.2 + dfsg-10)但是要安装4:4.8.2 + dfsg-2                  取决于:libqt4-script(= 4:4.8.2 + dfsg-10)但不会安装
                 取决于:libqt4-test(= 4:4.8.2 + dfsg-10)但不会安装
                 取决于:libqt4-xml(= 4:4.8.2 + dfsg-10)但要安装4:4.8.2 + dfsg-2                  取决于:libqtcore4(= 4:4.8.2 + dfsg-10)但是要安装4:4.8.2 + dfsg-2 libqt4-gui:取决于:   libqt4-designer(= 4:4.8.2 + dfsg-10)但它不会   安装
                取决于:libqt4-opengl(= 4:4.8.2 + dfsg-10)但是要安装4:4.8.2 + dfsg-2                 取决于:libqt4-svg(= 4:4.8.2 + dfsg-10)但不会安装
                取决于:libqtgui4(= 4:4.8.2 + dfsg-10)但要安装4:4.8.2 + dfsg-2

2 个答案:

答案 0 :(得分:0)

假设存在某种格式故障:

Depends: libqtcore4 (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed libqt4-gui : Depends: libqt4-designer (= 4:4.8.2+dfsg-10) but it is not going to be installed

(所以实际上它可能是:

Depends: libqtcore4 (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed
libqt4-gui : Depends: libqt4-designer (= 4:4.8.2+dfsg-10) but it is not going to be installed

)然后这应该做:

sed 's/.*Depends: \([^ ]*\) .*/\1/' lib-dep-list

给定数据文件lib-dep-list

libqt4-core : Depends: libqt4-dbus (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed
Depends: libqt4-network (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed
Depends: libqt4-script (= 4:4.8.2+dfsg-10) but it is not going to be installed
Depends: libqt4-test (= 4:4.8.2+dfsg-10) but it is not going to be installed
Depends: libqt4-xml (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed
Depends: libqtcore4 (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed
libqt4-gui : Depends: libqt4-designer (= 4:4.8.2+dfsg-10) but it is not going to be installed
Depends: libqt4-opengl (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed
Depends: libqt4-svg (= 4:4.8.2+dfsg-10) but it is not going to be installed
Depends: libqtgui4 (= 4:4.8.2+dfsg-10) but 4:4.8.2+dfsg-2 is to be installed

输出结果为:

libqt4-dbus
libqt4-network
libqt4-script
libqt4-test
libqt4-xml
libqtcore4
libqt4-designer
libqt4-opengl
libqt4-svg
libqtgui4

答案 1 :(得分:0)

使用awk

 awk -v RS="Depends:" 'NR>1{print $1}' temp.txt