user3022917 user3022917 - 2 years ago 191
Bash Question

if grep value greater than 1000 then

I want to grep "priority=" in a file where the value of "priority=" is greater than 1000.

I tried something like this:

if grep -q "priority=[ >1000 ]" file; then
echo "[!] Unnatural priority"

<intent-filter android:priority="2147483647">

Answer Source

You could use this Perl one-liner:

perl -lne 'print "[!] Unnatural priority" if /priority="(\d+)"/ && $1 > 1000'

Capture the digits in priority="X" and print the warning if the value is greater than 1000.

You can also do this in native bash if you want:

while read -r line; do 
    if [[ $line =~ priority=\"([[:digit:]]+)\" ]] && (( BASH_REMATCH[1] > 1000 )); then
        echo "[!] Unnatural priority"
done < file
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download