简体   繁体   中英

output of two command need to be added as columns awk

I have a file which contains Package name and its Release.The line Release change has both old version and new version:

grep -A 2 'Package list' pkglist
    Package list:   xorg-x11-drv-ati-firmware-7.6.1-3.el6_9.noarch
    Repository:     /Linux/6.9/rpms/xorg-x11-drv-ati-firmware-7.6.1-4.el6.noarch.rpm
    Release Change: 3.el6_9 --> 4.el6

    Package list:   yum-plugin-fastestmirror-1.1.30-40.0.1.el6.noarch
    Repository:     /Linux/6.9/rpms/yum-plugin-fastestmirror-1.1.30-42.0.1.el6_10.noarch.rpm
    Release Change: 40.0.1.el6 --> 42.0.1.el6_10

    Package list:   yum-utils-1.1.30-40.0.1.el6.noarch
    Repository:     /Linux/6.9/rpms/yum-utils-1.1.30-42.0.1.el6_10.noarch.rpm
    Release Change: 40.0.1.el6 --> 42.0.1.el6_10

I need formatted output as three columns with 1st column as pkgname 2nd column as 'old version' and 3rd column as 'new version' :

 xorg-x11-drv-ati-firmware-7.6.1-3.el6_9.noarch 3.el6_9 4.el6
    yum-utils-1.1.30-40.0.1.el6.noarch 40.0.1.el6 42.0.1.el6_10
    yum-utils-1.1.30-40.0.1.el6.noarch 40.0.1.el6 42.0.1.el6_10

What I am trying is:

grep -i 'Package list' pkglist |  awk '{print $3}'
    xorg-x11-drv-ati-firmware-7.6.1-3.el6_9.noarch
    yum-plugin-fastestmirror-1.1.30-40.0.1.el6.noarch
    yum-utils-1.1.30-40.0.1.el6.noarch



 grep -A 2 'Package list' pkglist | grep -i 'Release' | awk '{print $3,$5}'
    3.el6_9 4.el6

    40.0.1.el6 42.0.1.el6_10

    40.0.1.el6 42.0.1.el6_10

The above two command output needs to be added as three columns in each line.

awk '/Package list/{printf $3 OFS}/Release Change/{print $3, $5}' pkglist

Returns

xorg-x11-drv-ati-firmware-7.6.1-3.el6_9.noarch 3.el6_9 4.el6
yum-plugin-fastestmirror-1.1.30-40.0.1.el6.noarch 40.0.1.el6 42.0.1.el6_10
yum-utils-1.1.30-40.0.1.el6.noarch 40.0.1.el6 42.0.1.el6_10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM