Parsing problem

Hello,
I have a similar problem so I continue this thread.
I have:

my_script_to_format_nicely_bdf.sh | grep "RawData" |tr -s ' '|cut -d' ' -f 4|tr -d '%'

So it supposed to return the percentage used of RawData FS:
80
(Want to use it in a alert script)
However I also have a RawData2 FS so it will output both:
80
60

So in the grep part how can I declare that there is no character after RawData like RawData2?

Thanks in advance

Easiest would be to post the unfiltered output of your script.

Sorry for hijacking. I thought it will be better to continue as it is a similar case.

What do you mean unfiltered output?

---------- Post updated at 02:51 PM ---------- Previous update was at 02:48 PM ----------

./bdf_rep.sh | grep "RawData" |tr -s ' '|tr -d '%'

138048 122619 15429.5 89 /RawData
193632 116719 76399.9 60 /RawData2

So i need only to display the first line how do I filter this out with grep ?

To grep FS 80% or more :

df -k | grep [890][0-9]%

Does not work cause the output of df is messy ( due to long FS names)

Try this

./bdf_rep.sh | grep "RawData$"

regards,
Ahamed

try :

df -k | cat | grep [890][0-9][%]

---------- Post updated at 02:17 PM ---------- Previous update was at 02:17 PM ----------

could you post an example of output of
./bdf_rep.sh

With unfiltered output I mean to post with using code tags the output of your script my_script_to_format_nicely_bdf.sh or ./bdf_rep.sh , so we can maybe easier spot the problem.

No output

./bdf_rep.sh

TOTAL SIZE (MB)       USED (MB)   FREE (MB)   USAGE     FILESYSTEM
138048                116729      21319.5     85%       /RawData
9000                  2774.99     6179.58     31%       /var
193632                116719      76399.8     60%       /RawData2
780.68                52.4531     650.156     7%        /stand
.
.
.

Don't let bdf confuse you
I just need the expression to grep RawData but not RawData2 and problem solved

./bdf_rep.sh| awk '$NF ~ /RawData$/ {sub(/%/,"",$4); print $4}'

Had to edit, had an error in it.

./bdf_rep.sh |  nawk '$NF ~ "RawData$" {print $(NF-1)+0}'

1 Like

Nope :frowning:

Yeap :slight_smile:

"Nope" is not a helpful feedback. Expect the same level of help.....

1 Like

No ouput from zaxxon

Works for vgersh99 (with awk. nawk N/A)

---------- Post updated at 03:44 PM ---------- Previous update was at 03:41 PM ----------

So if I include my bdf_rep script, complete commands is:

#!/usr/bin/sh
bdf |sed -e 's/^\/[^ ]* //' -e 's/^[ \t]*//' | grep -v -e "Filesystem" -e /dev |tr -s ' ' | awk '{printf("%-22s%-12s%-12s%-10s%-20s\n",$1/1024,$2/1024,$3/1024
,$4,$5,$6)}' | sort -n -r -k 4 | awk '$NF ~ "RawData$" {print $(NF-1)+0}'

:slight_smile:

Just for completeness, it works for me:

$> cat infile
TOTAL SIZE (MB)       USED (MB)   FREE (MB)   USAGE     FILESYSTEM
138048                116729      21319.5     85%       /RawData
9000                  2774.99     6179.58     31%       /var
193632                116719      76399.8     60%       /RawData2
780.68                52.4531     650.156     7%        /stand
$> awk '$NF ~ /RawData$/ {sub(/%/,"",$4); print $4}' infile
85

Anyhow, you got a solution from vgersh99.

most likely you don't need so many piped filters. What you're after can easily be done with a single awk (saving on CPU and the confusion).

Display FS whose theshold exceed or equal 80

$ ./bdf_rep.sh | awk '$4+0>=80{print$5,$4+0}'
/RawData 85
/RawData2 100
/stand 95
$ ./bdf_rep.sh | awk '$4+0>=80{print$5,$4}' mdf
/RawData 85%
/RawData2 100%
/stand 95%
$ ./bdf_rep.sh | awk '$4+0>=80{print$5}' mdf
/RawData
/RawData2
/stand