Technas
Technas

Reputation: 17

how can i cut off the strings from an output in Bash shell?

The command i run is as follows:

rpm -qi setup | grep Install

The output of the command:

Install Date: Do 30 Jul 2020 15:55:28 CEST

I would like to edit this output further more in order to remain with just: 30 Jul 2020

And the rest of the output not to be displayed.

What best editing way in bash can i possibly simply get this end result?

Upvotes: 0

Views: 135

Answers (2)

fpmurphy
fpmurphy

Reputation: 2537

You can do it using just rpmqueryformat and bashprintf:

$ printf '%(%d %b %Y)T\n' $(rpm -q --queryformat '%{INSTALLTIME}\n' setup)
29 Apr 2020

Upvotes: 1

Timur Shtatland
Timur Shtatland

Reputation: 12347

Use grep -Po like so (-P = use Perl regex engine, and -o = print just the match, not the entire line):

echo '**Install Date: Do 30 Jul 2020 15:55:28 CEST**' | grep -Po '\d{1,2}\s+\w{3}\s+\d{4}'

You can also use cut like so (-d' ' = split on blanks, -f4-6 = print fields 4 through 6):

echo '**Install Date: Do 30 Jul 2020 15:55:28 CEST**' | cut -d' ' -f4-6

Output:

30 Jul 2020

Upvotes: 2

Related Questions