Issue
Can someone please help me with a regular expression to get the percentage from the below bash output through regex?
Get:11 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 libvlc$
Get:12 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 fonts-freefont-ttf$
40% [12 fonts-freefont-ttf 855 kB/4,140 kB 21%]
I just need to get the 40% from the above example..
Thanks.
Solution
awk '$1 ~ /[[:digit:]]{1,3}%/ { print $1 }'
Check that the first delimited piece of the line pattern matches to 1-3 digits followed by a %. If it does, print the first piece.
Answered By - Raman Sailopal