Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following output of my script:

panos@panos:~/scripts> ./list_packages openSUSE-2016-254
zypper-aptitude.noarch : 1.12.23-1.1 update needed
zypper-log.noarch : 1.12.23-1.1 update needed
libsolv-debugsource : None not installed
libsolv-demo : None not installed
libsolv-demo-debuginfo : None not installed
libsolv-devel : None not installed
libsolv-devel-debuginfo : None not installed
libsolv-tools : 0.6.14-1.1 update needed
libsolv-tools-debuginfo : None not installed
perl-solv : None not installed
perl-solv-debuginfo : None not installed
python-solv : 0.6.14-1.1 update needed
python-solv-debuginfo : None not installed
ruby-solv : None not installed
ruby-solv-debuginfo : None not installed
libzypp : 15.19.5-1.1 update needed
libzypp-debuginfo : None not installed
libzypp-debugsource : None not installed
libzypp-devel : None not installed
libzypp-devel-doc : None not installed
zypper : 1.12.23-1.1 update needed
zypper-debuginfo : None not installed
zypper-debugsource : None not installed

The output is generated based on some if-else statements. Let me give you the three echo commands used in my source code:

echo "$pkg : $pkg_version update needed"
echo "$pkg : $new_version updated"
echo "$pkg : None not installed"

My problem is that is would like them to be in columns, something like:

$pkg\t$pkg_version\t$message

But because some packagenames are >8 characters longs, the whole 'tab'-thing, gets ugly. Any suggestions?

share|improve this question
up vote 5 down vote accepted

There are two ways :

  1. Use bash' printf function to print and format your output (instead of echo)
  2. Use column -s : -t command

./list_packages openSUSE-2016-254 | column -s : -t 
zypper-aptitude.noarch     1.12.23-1.1 update needed
zypper-log.noarch          1.12.23-1.1 update needed
libsolv-debugsource        None not installed
libsolv-demo               None not installed
libsolv-demo-debuginfo     None not installed
libsolv-devel              None not installed
libsolv-devel-debuginfo    None not installed
libsolv-tools              0.6.14-1.1 update needed
libsolv-tools-debuginfo    None not installed
perl-solv                  None not installed
perl-solv-debuginfo        None not installed
python-solv                0.6.14-1.1 update needed
python-solv-debuginfo      None not installed
ruby-solv                  None not installed
ruby-solv-debuginfo        None not installed
libzypp                    15.19.5-1.1 update needed
libzypp-debuginfo          None not installed
libzypp-debugsource        None not installed
libzypp-devel              None not installed
libzypp-devel-doc          None not installed
zypper                     1.12.23-1.1 update needed
zypper-debuginfo           None not installed
zypper-debugsource         None not installed

share|improve this answer
    
that's what I tried also, but if you see even from your output, there is no clear distinction between the version (either number or 'none') and the status of the package (either not installed or update needed). – drpaneas Feb 24 at 9:11
1  
Solution to your problem is fairly simple IMHO. Instead of using mix of colon and tabs just do : echo "$pkg,$pkg_version,$message in your script. Then pipe the output to column -s , -t - is this what you want ? :) – KWubbufetowicz Feb 24 at 9:20
    
that one worked like a charm :) Thank you! – drpaneas Feb 24 at 9:39

You can use use something like: while read -r arg1 arg2; do awk '{print "package: $arg1 version: $arg1}';done < input file

So the idea is that arg1 will be always the 1st word in the line, arg2 will be the second one etc. You can use if grep etc to achieve the desired goal. Hope that helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.