Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim leading whitespace using awk command

Tags:

awk

I have seen the other examples and posts but just can't seem to get this working. I have some lparstat output which looks like:

Partition  Number                           :  1
Type                                       :  Dedicated-SMT
Mode                                       : Capped
Entitled  Capacity                          : 4,00
Partition  Group-ID                         : 32769
Shared Pool  ID                             : -

I would like to get the Capped value.

I have the following command however need to elimanate the leading whitespace:

cat lparstat.out | egrep '^Mode' | awk -F: '{ print $2 }'

Any suggestion on how to modify the awk command appreciated. I don't want to pipe to sed.

like image 708
dross Avatar asked Oct 21 '25 01:10

dross


1 Answers

awk -F '  *: ' '$1=="Mode"{print $2}' lparstat.out

or with a regex:

awk -F ': ' '/^Mode/{print $2}' lparstat.out

Output:

Capped
like image 104
Cyrus Avatar answered Oct 23 '25 21:10

Cyrus