Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to grep rows that have value less than or equal to value

size=139
size=9292
size=140
size=139
size=139
size=10213
size=139
size=140
size=11186
size=139
size=139
size=140
size=12342
size=139
size=139
size=140
size=11360

How can I grep rows that has greater value than 1000 from size.txt ?

Also, is there any way that I could find this information from entire folder, which has many txt files like this ?

like image 839
Ben Avatar asked Dec 11 '22 23:12

Ben


2 Answers

With awk:

awk -F= '$2 > 1000' filename

This can be used with many file names:

awk -F= '$2 > 1000' *

Or combined with find to do it to subfolders as well:

find directory -type f -exec awk -F= '$2 > 1000' '{}' \;

For the latter two, it may be desirable to print the file name as well as the actual result (mimicking the behavior of grep), which could be achieved like this:

awk -F= '$2 > 1000 { print FILENAME ": " $0 }' *
like image 56
Wintermute Avatar answered Apr 02 '23 17:04

Wintermute


With bash builin commands:

while IFS="=" read variable value; do
  [[ $value -gt 1000 ]] && echo "${variable}=${value}"
done < file

Output:

size=9292
size=10213
size=11186
size=12342
size=11360
like image 34
Cyrus Avatar answered Apr 02 '23 18:04

Cyrus