Parsing a file with different patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing a file with different patterns
# 1  
Old 04-01-2015
Parsing a file with different patterns

I have a text file like this , where the same set of three lines repeat with different values.
Code:
INFO:  processing now 03/25/2015-00:06:05 03/25/2015-00:16:04
------Invoking myexe table=table1 
INFO  25-03 00:20:26,801 - Finished processing (I=0, O=57, R=57, W=57, U=0, E=0)
INFO:  processing now 03/25/2015-00:20:09 03/25/2015-00:25:04
------Invoking myexe table=table2 
INFO  25-03 00:20:26,801 - Finished processing (I=0, O=57, R=59, W=57, U=0, E=0)

0
Now my requirement is to parse this file and create an output like this.
Code:
 03/25/2015-00:06:05 03/25/2015-00:16:04  table1 W=57
 03/25/2015-00:20:09 03/25/2015-00:25:04 table2 W=57

As each line has a different pattern, I am not sure how to do this in a single shot. Please help. .
# 2  
Old 04-01-2015
This works...

file a.awk contains

Code:
/^INFO:/ {
        dateTimeSTART=$4
        dateTimeEND=$5
        }
/^-----/ {
        split($0,a,"=")
        table=a[2]
        }
/^INFO / {
        split($10,a,",")
        W=a[1]
        print dateTimeSTART,dateTimeEND,table,W

Then do

Code:
awk -f a.awk input-file > saved.file

This User Gave Thanks to blackrageous For This Post:
# 3  
Old 04-01-2015
Hello LakshmiKumari,

Following may help you in same.
Code:
awk -F, '/INFO:  processing now/{match($0,/[0-9][0-9]\/.*/);A=substr($0,RSTART,RLENGTH);}{if($0 ~ /^-/){gsub(/.*table=/,X,$0);A=A OFS $0;}};{if($0 ~ /Finished processing/){print A OFS $5}}'  Input_file

Output will be as follows.
Code:
03/25/2015-00:06:05 03/25/2015-00:16:04 table1   W=57
03/25/2015-00:20:09 03/25/2015-00:25:04 table2   W=57

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 4  
Old 04-01-2015
Try also
Code:
awk     '/^INFO:/       {sub (/^.*now /,""); printf "%s ", $0}
         /^-----/       {sub (/^.*=/, ""); printf "%s ", $0}
         /^INFO /       {sub (/,$/, "", $10); printf "%s\n", $10}
        ' file
03/25/2015-00:06:05 03/25/2015-00:16:04 table1  W=57
03/25/2015-00:20:09 03/25/2015-00:25:04 table2  W=57

This User Gave Thanks to RudiC For This Post:
# 5  
Old 04-01-2015
Thanks a lot to everyone who replied. It really helps Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

3. Shell Programming and Scripting

Replace patterns in a file

Hi all, I here have a file which contains a list of files inside, all of which have the suffix ".log". And now I would wish to replace all the pattern ".log" with ".log.bz2" there. So how could I archive this? Thanks (4 Replies)
Discussion started by: isaacniu
4 Replies

4. Shell Programming and Scripting

Extract certain patterns from file.

Hi All, I tried extracting this pattern using grep but it did not work. What I have is a file which has contents like this: file:///channel/add-adhd.html file:///channel/allergies.html file:///channel/arthritis.html http://mail.yahoo.com/ http://messenger.yahoo.com/... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

5. Shell Programming and Scripting

parsing filename and grabbing specific string patterns

Hi guys...Wow I just composed a huge post and it got erased as I was logged out automatically Anyways I hope someone can help me out here. So the task I'm working on is like this I have a bunch of files that I care about sitting in a directory say $HOME/files Now my job is to go and loop... (6 Replies)
Discussion started by: rukasetsuna
6 Replies

6. Shell Programming and Scripting

Finding patterns in a file

Hi, I have a file with 3 columns and I want to find when the average number of rows on column 3 is a certain value. The output will be put into another file indicating the range. Here is what I mean (file is tab separated): hhm1 2 0 hhm1 4 0.5 hhm1 6 0.3 hhm1 8 -1.4... (2 Replies)
Discussion started by: kylle345
2 Replies

7. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies

8. Shell Programming and Scripting

To find 3 patterns in a file

hy i have a requirement in which my script needs to find 3 patterns in a file and if any pattern is missing it should sent a mail Patterns Interval60min_Daily_readings$a.txt Interval_Daily_readings$a.txt Daily_readings$a.txt Basically i want to test for the above Patterns in the... (2 Replies)
Discussion started by: ali560045
2 Replies

9. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

10. Shell Programming and Scripting

grep patterns - File

Hi I have 3 patterns for example to be searched. These three patterns are available in file1. The patterns to be searched are in file2. I want to search the pattern of file1 to file2. Can any one help with example? Regards Dhana (1 Reply)
Discussion started by: dhanamurthy
1 Replies
Login or Register to Ask a Question