1

Listing the available patches in openSUSE results in the following output.

The command that results int the details below is zypper patches. The same result is also displayed when running the command zypper list-patches -a

Loading repository data...
Reading installed packages...
Repository                        | Name               | Category    | Severity  | Interactive | Status     | Summary                                                                                           
----------------------------------+--------------------+-------------+-----------+-------------+------------+---------------------------------------------------------------------------------------------------
openSUSE-Leap-15.0-Update         | openSUSE-2018-1000 | recommended | moderate  | ---         | not needed | Recommended update for gnuhealth, proteus, tryton, trytond, trytond_purchase, trytond_stock_supply
openSUSE-Leap-15.0-Update         | openSUSE-2018-1004 | security    | low       | ---         | not needed | Security update for ffmpeg-4                                                                      
openSUSE-Leap-15.0-Update         | openSUSE-2018-1005 | security    | moderate  | ---         | not needed | Security update for chromium                                                                      
openSUSE-Leap-15.0-Update         | openSUSE-2018-1006 | security    | moderate  | ---         | applied    | Security update for okular                                                                        
openSUSE-Leap-15.0-Update         | openSUSE-2018-1007 | recommended | moderate  | ---         | applied    | Recommended update for tigervnc     

In an attempt to sort "Status" using the command sort -k 6,6 listing.txt | less for example yields the following output.

----------------------------------+--------------------+-------------+-----------+-------------+------------+---------------------------------------------------------------------------------------------------
Loading repository data...
Reading installed packages...
openSUSE-Leap-15.0-Update-Non-Oss | openSUSE-2018-1082 | recommended | moderate  | ---         | not needed | Security update for opera                                                                         
openSUSE-Leap-15.0-Update-Non-Oss | openSUSE-2018-1240 | recommended | moderate  | ---         | not needed | Recommended update for opera                                                                      
openSUSE-Leap-15.0-Update-Non-Oss | openSUSE-2018-1294 | recommended | low       | ---         | not needed | Recommended update for Regina-REXX, THE, ooRexx                                                   
openSUSE-Leap-15.0-Update         | openSUSE-2018-1000 | recommended | moderate  | ---         | not needed | Recommended update for gnuhealth, proteus, tryton, trytond, trytond_purchase, trytond_stock_supply
openSUSE-Leap-15.0-Update         | openSUSE-2018-1007 | recommended | moderate  | ---         | applied    | Recommended update for tigervnc    
Repository                        | Name               | Category    | Severity  | Interactive | Status     | Summary                   

In checking if the delimiter is a combination of spaces and tabs using the syntax highlighting rules in vim, it returns only spaces.

:syntax on
:set syntax=whitespace 

enter image description here

It seems that the file may using multiple delimiters.

  • What is the most effective way of determining the delimiters in use?
  • What would be the best and simplest way to sort the columns based on the delimiters in use?
  • @JeffSchaller - I updated the question with the commands that return the output. – Motivated Jan 20 at 17:34
2

This should do, unless you want to keep the header in place:

tail -n +5 listing.txt | sort -b -k6 -t'|'

You can omit the -b option of sort ("ignore leading blanks) if the file is using white space regularly (ie. it doesn't mix | applied and | applied).

But I guess that a) that program probably has some options to tweak its format into something more machine-readable b) you'll be better off with just eg. awk -F'|' '$6~/not needed/' instead of sort.

  • It's probably best not to assume there are 5 patches every single time. – Niko Gambt Jan 20 at 17:18
  • @NikoGambt tail +5 is not the same as tail -5 – mosvy Jan 20 at 17:22
  • Ah, my mistake. – Niko Gambt Jan 20 at 17:26
  • 1
    @Motivated corrected to a standard-compliant tail syntax. You can also use sed -n '5,$p' instead of tail -n +5. If you're using sort -k6,6 without a -t option, it will consider the 3rd | as the 6th field. – mosvy Jan 20 at 17:42
  • 1
    @Motivated You don't have to distinguish between spaces and tabs; the -b option of sort should cause it to ignore any leading blanks in the selected field(s), no matter if they're spaces or tabs. If you're concerned about the file containing nulls and other non-printable chars, you could check it with hexdump ;-) – mosvy Jan 20 at 17:54
0

You could use this:

awk 'NR<=4 {print $0; next } { print $0 | "sort -k6,6 -t\\|" }' listing.txt

It runs awk on listing.txt; instead you could pipe the data into awk (leaving out the listing.txt at the end, of course). The awk-script prints the first four header lines as they are. The rest of the lines is piped into sort. Sort sorts the 6th column, identifying it using a delimiter equal to the pipe symbol.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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