Skip to content
Advertisement

How to make GREP select only numeric values?

I use the df command in a bash script:

JavaScript

This script returns:

JavaScript

But I need only numbers (to make the next comparison). If I use the grep regex without the dot:

JavaScript

I receive nothing. How to fix?

Advertisement

Answer

If you try:

JavaScript

It returns:

JavaScript

Here’s the details on the -o (or --only-matching flag) works from the grep manual page.

Print only the matched (non-empty) parts of matching lines, with each such part on a separate output line. Output lines use the same delimiters as input, and delimiters are null bytes if -z (–null-data) is also used (see Other Options).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement