Issue
I am using the command to get the list of patches:
sudo yum --setopt=history_list_view=commands history list all
The output:
ID | Command line | Date and time | Action(s) | Altered
13 | remove wget | 2018-10-16 08:56 | Erase | 2
12 | install sssd-1.12.4-47.e | 2018-10-16 03:09 | Update | 4 ss
11 | install unzip-6.0-2.el6_ | 2018-10-15 09:27 | Update | 1
10 | install sqlite-3.6.20-1. | 2018-10-15 09:26 | Update | 1
9 | install pam-1.1.1-20.el6 | 2018-10-15 09:22 | Update | 1
8 | install libxml2-python-2 | 2018-10-15 09:20 | Update | 2
7 | install curl.x86_64 | 2018-10-15 08:56 | Update | 2
6 | install dhclient.x86_64 | 2018-10-15 08:55 | Update | 2
5 | install openssh.x86_64 | 2018-10-15 08:50 | Update | 3
4 | install samba-winbind-3. | 2018-10-15 04:59 | Update | 4
3 | install zsh-html.x86_64 | 2018-10-12 06:57 | Install | 1
2 | install samba | 2017-01-05 03:17 | I, U | 5
1 | install wget | 2017-01-05 03:08 | Update | 1
How can I process this and get the patch name only from the command line column?
Solution
You can get the package name only by using awk
such way:
sudo yum --setopt=history_list_view=commands history list all | awk -F '|' 'NR>2{print $2}' | awk 'NF{print $2}'
The first awk expression splits every string by |
-character and gives you the second column (except for the first two lines NR>2
which describe the header of the table). The second awk expression splits second column by space-character and gives you a package name, along the way filtering empty lines (more info about NF in awk).
The output will be like:
curl.x86_64
dhclient.x86_64
openssh.x86_64
zsh-html.x86_64
samba
wget
If you need some filtering e.g. by Action
-field, the additional grep
is needed firstly.
Answered By - z0lupka Answer Checked By - Senaida (WPSolving Volunteer)