Grep: Using -w and -o combined

Issue

How can I combine this 2 commands?

df -m --output=target,size | grep -w /dbm

/dbm                 394257

df -m --output=target,size| grep -o '[0-9]\+'

3444
865636
394257
224

I want to get the following result:

394257

And is it possible to multiply the number within 1 command?
For example I want the result(394257) multiplied by 1000 to get the following result:

394257000

Searched the internet but here I come across python script which I am trying to avoid.
Have read some documentation about Grep but couldnt resolve my issue.

Solution

You can replace grep with awk like this:

df -m --output=target,size | awk '$1 == "/dbm" {print $2 * 1000}'

394257000

Answered By – anubhava

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published