0
cat pkg.temp
ca-certificates-2017.2.14-65.0.1.el6_9.noarch
glusterfs-3.7.9-12.el6.x86_64
glusterfs-api-3.7.9-12.el6.x86_64
glusterfs-api-devel-3.7.9-12.el6.x86_64
glusterfs-client-xlators-3.7.9-12.el6.x86_64

Here is a file , I want the output as :

PkgName                        Version
ca-certificates                2017.2.14-65.0.1.el6_9.noarch
glusterfs                      3.7.9-12.el6.x86_64
glusterfs-api-devel            3.7.9-12.el6.x86_64
glusterfs-client-xlators       3.7.9-12.el6.x86_64

This way I get unwanted hyphen at the last:

$ awk -F'[[:digit:]]' '{ print $1}'
ca-certificates-
glusterfs-
glusterfs-api-
glusterfs-api-devel-
glusterfs-client-xlators-

While printing $2 wont display my version either

awk -F'[[:digit:]]' '{ print $2}' /tmp/Version-pkgs

.
.
.
.
.
.

1 Answer 1

2

If you are confident that the delimiter combination is "-" followed by a digit, you can use sed to replace that dash with a space. You can the pipe this through awk to do some formatted printing. Something like this:

sed -e 's/-\([0-9]\)/ \1/' _file_ | awk 'BEGIN {printf("%-30s %s\n", "PkgName", "Version")} {printf("%-30s %s\n", $1, $2)}'

Hope this helps.

1
  • 3
    +1 although personally I'd replace the awk fixed-width formatting with a column -t Nov 27, 2018 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .