AWK to separate numbers from logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK to separate numbers from logs
# 1  
Old 09-01-2009
AWK to separate numbers from logs

Hello friends,

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

Code:
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 )

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

or should it be something like:
Code:
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.
# 2  
Old 09-01-2009
Try:
Code:
awk '/[Ee]stimated/ {gsub(/\(|\..*/,"",$5);print $5}' mylog.txt

# 3  
Old 09-01-2009
One way:

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

# 4  
Old 09-01-2009
Hello again,

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

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

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

Code:
awk '/[Ee]stimated/ {print $5}' mylog.txt

gives something like the form "(XXXX.YYMB)." X,Y integers
# 5  
Old 09-01-2009
try nawk/gawk under solaries.
# 6  
Old 09-01-2009
Quote:
Originally Posted by panyam
try nawk/gawk under solaries.
Or /usr/xpg4/bin/awk on Solaris.
# 7  
Old 09-01-2009
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:

Code:
/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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk separate files to one directory

I am trying to output all files that are made by this awk to a specific directory. awk -F '' '{f = $3 ".txt"; print > f}' input.txt Since the actual data has several hundred files I redirect the output (well tried to) to a directory. awk -F '' '{f = $3 ".txt"; close($3 ".txt")} print >... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Csv file separate using awk

Hi, I have file like below apple,orange,pineapple,pappya,guva,avocado want to store as apple orange pineapple pappya I tried below command to seprate first field command1: (3 Replies)
Discussion started by: stew
3 Replies

3. Shell Programming and Scripting

Line numbers and exception to be caught in logs

Hi Folks, I have just basic queries is that suppose I have to monitor the logs then there is a command , suppose I have to monitor the abc.log which is updating dynamically within seconds so the command will be after going to that directory is .. tail -f abc.log Now please advise what about... (1 Reply)
Discussion started by: punpun66
1 Replies

4. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

5. Shell Programming and Scripting

Separate two numbers

I would like to separate number by space so that 121231212 222111212 would be 1 2 1 2 3 1 2 1 2 2 2 2 1 1 1 2 1 2 Thanks! (2 Replies)
Discussion started by: johnkim0806
2 Replies

6. Shell Programming and Scripting

Awk variable in a separate file

Hi all, I have a requirement to put all the varibles used in an awk command in a separate file. This is because i have arround 100 variables used in an awk command. So i want to put all the variables used for the awk command in a separate file. Please help me on this. Thanks in adv. (6 Replies)
Discussion started by: gani_85
6 Replies

7. Shell Programming and Scripting

separate two numbers separated by :

Hi all i have a data of this form 10.12.4.22:138 10.12.2.50:137 10.20.2.24:1027 10.12.2.44:138 10.12.2.44:137 10.0.4.38:58871 10.13.3.19:138 i need to separate the number out which is at the last and after ':' Please help me out Thanx in advance (5 Replies)
Discussion started by: vaibhavkorde
5 Replies

8. Shell Programming and Scripting

separate numbers in a file

I have this command in a shl (UNIX) to find the lates file that start with EMT in a directory file=$(ls -tr $EMT*.dat | tail -1) # Select the latest file It finds: EMT345.dat then I have to be able to separate EMT AND the numbers 345 and stored 345 in a variable and incremented, so my new... (7 Replies)
Discussion started by: rechever
7 Replies

9. Shell Programming and Scripting

awk command to separate a field

I have a log file that I am trying to convert. File contents something like this: aaaaa bbbbbb cccc dddddd\123 eeeee ffffffff I am trying to output the fields in a different order and separate field 4 so that the "123" and "dddddd" can be output separately. for example bbbbbb aaaaa 123... (5 Replies)
Discussion started by: jake1988
5 Replies

10. UNIX for Dummies Questions & Answers

how to separate numbers and words from a file using shell scripts

Hi, How to separate numbers and words(with full alphabets) in a particular file and store it in two different files. Please help me out for this.Using shell scripting. :confused::confused: (1 Reply)
Discussion started by: kamakshi s
1 Replies
Login or Register to Ask a Question