Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is in reference to another question: How do I use robocopy to list all files over a certain size recursively?

I would like to parse output of a command (or cat a log file) and find a string value, convert it to an integer and then see if that integer value is greater than a given integer.

For instance, given the line:

      *EXTRA File          78223    C:\_Google.Enterprise.Contract.2010-06-01.pdf

I'd like to compare '78223' to '10485760'. Is this possible with grep or sed?


share|improve this question
You probably awk, or a scripting language for numerical comparisons. – Zoredache Sep 2 '11 at 19:48
Thanks, I'll look into using awk. – mbrownnyc Sep 2 '11 at 19:52
Tho should have been moved to the UNIX stackexchange. – Jim B Dec 3 '15 at 5:30
@JimB : possibly, but Questions older than 60 days can't be migrated. – HBruijn Dec 4 '15 at 10:17
It's a Windows question... just gaze upon the path. – mbrownnyc Dec 24 '15 at 12:42
up vote 11 down vote accepted

Use awk as follows:

$ echo '*EXTRA File     78223    C:\foo.pdf' | awk '$3 > 1048576 {print $0;}'
$ echo '*EXTRA File     78223    C:\foo.pdf' | awk '$3 > 40000 {print $0;}'
*EXTRA File     78223    C:\foo.pdf
share|improve this answer
Thanks. Not familiar with awk. It looks to be very handy. – mbrownnyc Sep 2 '11 at 20:15

Also - if you're using a Unix-like userland (like UnxUtils or Cygwin, if you're on Windows), you can use find with the -size parameter to get your file list directly, and then pipe to xargs and do whatever you're trying to do with the selected files.

The general answer to your question (interesting comparisons and other operations) is indeed awk or bash (with bc) or perl - but the specific scenario lends itself to find.

share|improve this answer
Bash can natively perform integer math, check out – astrostl Sep 2 '11 at 20:30
find can also -exec rather than piping to xargs. If xargs-like "all arguments in one command" style is preferred, terminate with + rather than ; Check out… :) – astrostl Sep 2 '11 at 20:32

In pure Bash:

while read -r _ _ size _; do ((size > 10485760)) && echo "hit"; done < foo.log
share|improve this answer
This can be easily modified to report any field(s) or the entire line if there is a match, and/or custom-define the comparison integer at runtime. If you want that, just LMK. – astrostl Sep 2 '11 at 20:22

Perl can be used similarly to awk:

echo '*EXTRA File 78223 C:\foo.pdf' | perl -ane 'print if $F[2] > 40000'

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.