grep/awk usage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep/awk usage
# 1  
Old 07-07-2010
grep/awk usage

Hi everybody, i know this question is common on the forum and i've searched for my answer but haven't quite found it.
I'm trying to extract some values from a number of log files which look like this:

Code:
Peak Power Consumption: 0.20777 Watts

Observed Average Power: 0.1414794247 Watts

The other log files are similar where the value i want to extract is behind a word and a colon (like here 'Peak Power Consumption:')

I want to extract the values behind the colons using grep (or something else, whatever is easiest) and i want to use the text (or a piece of the text) before the colon and the colon as pattern so i can do the same trick to the other log files i have to process.

Anyone has any ideas?
Thanks a lot in advance!
# 2  
Old 07-07-2010
Hi,

Can you post the expected output ?
# 3  
Old 07-07-2010
Sure, i want to get variables in the script with the values, so for example after the grep i want to have:
$result1 = 0.20777
$result2 = 0.1414794247
# 4  
Old 07-07-2010
check if this would suffice you

Code:
 awk -F: '{print $1}' < filename

# 5  
Old 07-07-2010
This outputs:

Code:
Peak Power Consumption Oberserved Average Power

so not the desired output, but thanks for helping Smilie
# 6  
Old 07-07-2010
Code:
awk -F":" '{print $2}' testfile | awk '$1 ~ /[0-9]/ {print $1}'

This User Gave Thanks to pravin27 For This Post:
# 7  
Old 07-07-2010
Assuming you have the same unit always i.e watts and the colon appears only once in a line.

Code:
$ eval $(awk '/[a-zA-Z]+:/ { gsub(".*: ", "");gsub(" Watts", "");print "result"NR"="$0}' logfile)
$ 
$ 
$ echo $result2
0.20777
$ echo $result4
0.1414794247
$

If the scenario is different, please mention all the possible cases.
This User Gave Thanks to clx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

2. Homework & Coursework Questions

grep usage help?

Use and complete the template provided. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have to find all the files where the function sequentialInsert is called and the directory is ~cs252/Assignments/commandsAsst/project 2.... (2 Replies)
Discussion started by: jennkat
2 Replies

3. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

4. Shell Programming and Scripting

grep command usage

what is the grep command to get the second occurence of pattern in a file or how to do with sed ? (1 Reply)
Discussion started by: santosh1234
1 Replies

5. UNIX for Advanced & Expert Users

Grep usage

my file contains xxabced.p dlksfad; dflsdkjflkds flksdjflkdioewf erfsdlkfjsdla; dlkfjsd;lfkj msgdadf.p dslk kdjflksdjfl;asdfasdfjkljl fdsf;jd ppuskldf.p i want the output is xxabced.p msgdadf.p ppuskldf.p Can any one give the command? (1 Reply)
Discussion started by: kingganesh04
1 Replies

6. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

7. UNIX for Dummies Questions & Answers

Grep Usage

Hello, I am trying to use grep to locate multiple uses of the same word in the same line. The word has to be 3+ char, upper or lower or both. I tried this code <code> grep \({3,}\)*\1 i* </code> and i turned out zero results. Any ideas? ____________________________________________... (5 Replies)
Discussion started by: Omega1589
5 Replies

8. UNIX for Dummies Questions & Answers

Grep usage help

Hello, I have a list in .txt format of email addresses and I need to extract just a specific domain ... The list format is like: "123456";"user@domain.com";"email";"john";"name" "123457";"user2@domain.com";"email";"john";"name" "123458";"user3@domain.com";"email";"john";"name"... (7 Replies)
Discussion started by: holyearth
7 Replies

9. Shell Programming and Scripting

awk and grep command usage

hi Can anyone explain me how these two commands awk and grep works in a ksh shell Thanks Babu (1 Reply)
Discussion started by: ksmbabu
1 Replies

10. UNIX for Advanced & Expert Users

grep usage

grep can filter the text which want to display, but if I want it do not show the text specific in grep, how to do? thk a lot! (2 Replies)
Discussion started by: zp523444
2 Replies
Login or Register to Ask a Question