4
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 ?

Wintermute
  • 42,983
  • 5
  • 77
  • 80
Ben
  • 91
  • 1
  • 2
  • 9

3 Answers3

12

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 }' *
Wintermute
  • 42,983
  • 5
  • 77
  • 80
2

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
Cyrus
  • 84,225
  • 14
  • 89
  • 153
0
egrep "size=[0-9]{4}" size.txt
Walter A
  • 19,067
  • 2
  • 23
  • 43