AWK to separate numbers from logs

Hello friends,

Im trying to separate a number from a log, but it seems i need help here

awk '/[Ee]stimated/ {print $5}' mylog.txt
gives  (1515.45MB).

i need pure number part to use in a comparision loop so i want to separate the number part (but only 1515 not 1515.45 )

awk '/[Ee]stimated/ {print $5}' mylog.txt | awk '/^[(][.]$/ {print $1}'

or should it be something like:

awk '/[Ee]stimated/ {print $5}' mylog.txt | awk '/^[0-9]+[A-Z]$/ {print $1}'

i coudlnt find the right code even i tried (i dont have a good command of awk) so would like to get your help, thx.

Try:

awk '/[Ee]stimated/ {gsub(/\(|\..*/,"",$5);print $5}' mylog.txt

One way:

awk '/[Ee]stimated/ {sub("\(","",$5);print int($5)}' file

Hello again,

I tried both of the codes respectively that you suggested but has errors, changed some parts but couldnt solve :frowning:

server1{root}> awk '/[Ee]stimated/ {gsub(/\(|\..*/,"",$5);print $5}' mylog.txt 
awk: syntax error near line 1
awk: illegal statement near line 1
server1{root}> awk '/[Ee]stimated/ {sub("\(","",$5);print int($5)}' mylog.txt 
awk: syntax error near line 1
awk: illegal statement near line 1
awk '/[Ee]stimated/ {print $5}' mylog.txt

gives something like the form "(XXXX.YYMB)." X,Y integers

try nawk/gawk under solaries.

Or /usr/xpg4/bin/awk on Solaris.

Franklin you are great,thank you very much indeed for reminding me of /usr/xpg4/bin/awk ;when i run your and Klassh's command they both worked:

/usr/xpg4/bin/awk '/[Ee]stimated/ {gsub(/\(|\..*/,"",$5);print $5}' mylog.txt
/usr/xpg4/bin/awk '/[Ee]stimated/ {sub("\(","",$5);print int($5)}' mylog.txt
both gave  1515  thats what exactly i want.

you know always using normal awk (not from xpg4/bin ) you get used to it and when you face an error it just makes you think as if it is caused by bad code and misleads you.This reminds me of ggrep case, it only works from under /usr/sfw/bin/ that is forgettable (if you dont put it env path).

regards