Need help on appending all the lines in a file after a pattern is found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on appending all the lines in a file after a pattern is found
# 8  
Old 10-09-2012
did you try my code with nawk ?
# 9  
Old 10-17-2012
Yeah with ur code nawk works .. but the format of the log files has changed slightly.. it comes as follows
Code:
Sat,Oct,1,00:01:56,2011,Local,ESSBASE0,Info(1054014),Database,GETSPlan,loaded
Sat,Oct,1,00:01:56,2011,Local,ESSBASE0,Info(1051061),Application,GETSPlan,loaded,-,connection,established
Sat,Oct,1,00:02:09,2011,Local,ESSBASE0,Info(1054014),Database,GETS_SAL,loaded
Sat,Oct,1,00:02:09,2011,Local,ESSBASE0,Info(1051061),Application,GETS_SAL,loaded,-,connection,established
Sat,Oct,1,00:03:19,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,0,minutes
Sat,Oct,1,00:03:26,2011,Local,ESSBASE0,Info(1051131),Logging,out,user,maxluser,,,active,for,1,minute
Sat,Oct,1,00:03:36,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,0,minutes
Sat,Oct,1,00:05:00,2011,Local,ESSBASE0,Info(1051131),Logging,out,user,123457678,,,active,for,1,minute
Sat,Oct,1,00:17:41,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,maxluser,,,active,for,14,minutes
Sat,Oct,1,01:04:51,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,62,minutes
Sat,Oct,1,03:52:10,2011,Local,ESSBASE0,Info(1054014),Database,GETS_AR,loaded
Sat,Oct,1,03:52:10,2011,Local,ESSBASE0,Info(1051061),Application,GETS_AR,loaded,-,connection,established
Sat,Oct,1,04:01:55,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,9,minutes
Sat,Oct,1,04:02:18,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,10,minutes
Sat,Oct,1,04:11:55,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,6,minutes
Sat,Oct,1,04:12:18,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,7,minutes
Sat,Oct,1,06:52:50,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,maxluser,,,active,for,0,minutes
Sat,Oct,1,09:16:59,2011,Local,ESSBASE0,Info(1054014),Database,GETS_ORD,loaded
Sat,Oct,1,09:16:59,2011,Local,ESSBASE0,Info(1051061),Application,GETS_ORD,loaded,-,connection,established
Sat,Oct,1,09:43:01,2011,Local,ESSBASE0,Info(1054014),Database,Fx_Conv,loaded
Sat,Oct,1,09:43:01,2011,Local,ESSBASE0,Info(1054014),Database,Fx_Conv2,loaded
Sat,Oct,1,09:43:01,2011,Local,ESSBASE0,Info(1051061),Application,Fx_Conv,loaded,-,connection,established
Sat,Oct,1,09:43:11,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,maxluser,,,active,for,0,minutes
Sat,Oct,1,09:49:30,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,32,minutes

and i need it as follows
Code:
Sat,Oct,1,00:01:56,2011,Local,ESSBASE0,Info(1054014),Database,GETSPlan,loaded
Sat,Oct,1,00:01:56,2011,Local,ESSBASE0,Info(1051061),Application,GETSPlan,loaded,-,connection,established
Sat,Oct,1,00:02:09,2011,Local,ESSBASE0,Info(1054014),Database,GETS_SAL,loaded
Sat,Oct,1,00:02:09,2011,Local,ESSBASE0,Info(1051061),Application,GETS_SAL,loaded,-,connection,established
Sat,Oct,1,00:03:19,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,0,minutes,GETS_SAL
Sat,Oct,1,00:03:26,2011,Local,ESSBASE0,Info(1051131),Logging,out,user,maxluser,,,active,for,1,minute,GETS_SAL
Sat,Oct,1,00:03:36,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,0,minutes,GETS_SAL
Sat,Oct,1,00:05:00,2011,Local,ESSBASE0,Info(1051131),Logging,out,user,123457678,,,active,for,1,minute,GETS_SAL
Sat,Oct,1,00:17:41,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,maxluser,,,active,for,14,minutes,GETS_SAL
Sat,Oct,1,01:04:51,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,62,minutes,GETS_SAL
Sat,Oct,1,03:52:10,2011,Local,ESSBASE0,Info(1054014),Database,GETS_AR,loaded
Sat,Oct,1,03:52:10,2011,Local,ESSBASE0,Info(1051061),Application,GETS_AR,loaded,-,connection,established
Sat,Oct,1,04:01:55,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,9,minutes,GETS_AR
Sat,Oct,1,04:02:18,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,10,minutes,GETS_AR
Sat,Oct,1,04:11:55,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,6,minutes,GETS_AR
Sat,Oct,1,04:12:18,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,7,minutes,GETS_AR
Sat,Oct,1,06:52:50,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,maxluser,,,active,for,0,minutes,GETS_AR
Sat,Oct,1,09:16:59,2011,Local,ESSBASE0,Info(1054014),Database,GETS_ORD,loaded
Sat,Oct,1,09:16:59,2011,Local,ESSBASE0,Info(1051061),Application,GETS_ORD,loaded,-,connection,established
Sat,Oct,1,09:43:01,2011,Local,ESSBASE0,Info(1054014),Database,Fx_Conv,loaded
Sat,Oct,1,09:43:01,2011,Local,ESSBASE0,Info(1054014),Database,Fx_Conv2,loaded
Sat,Oct,1,09:43:01,2011,Local,ESSBASE0,Info(1051061),Application,Fx_Conv,loaded,-,connection,established
Sat,Oct,1,09:43:11,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,maxluser,,,active,for,0,minutes
Sat,Oct,1,09:49:30,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,123457678,,,active,for,32,minutes,Fx_Conv


PS: the lines containing 'connection,established
' have the application name and that application name has to be suffixed after the lines which are ending with minutes.
It would be really kind of u if u could give an explanation to the code as well

thanks in advance Smilie

Last edited by Franklin52; 10-17-2012 at 06:38 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed/awk join lines once pattern found

Hi all OS - RHEL6.4 I have input file -f1.txt I need to search line which starts with \Start and read next line till it gets blank line and join them all. I need to trim any trailing spaces for each line.So output.txt should be.. \Start\now\fine stepwatch this space for toolsends... (7 Replies)
Discussion started by: krsnadasa
7 Replies

2. Shell Programming and Scripting

Appending lines in a file

Hello, I have a file like: str1,"HEX"H,(39),info str2,"HEX"H,(854548),info str3,"HEX"H,'BGTOUR',info str4,"HEX"H,(534322),info str1,"HEX"H,,info str3,"HEX"H,'Landing',info str4,"HEX"H,'BG',info str1,"HEX"H,,info str3,"HEX"H,'Ay',info str1,"HEX"H,(27),info str2,"HEX"H,(854548),info... (2 Replies)
Discussion started by: apenkov
2 Replies

3. Shell Programming and Scripting

If first pattern is found, look for second pattern. If second pattern not found, delete line

I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :) I have the output of an ldapsearch that looks like this: dn: cn=sam,ou=company,o=com uidNumber: 7174 gidNumber: 49563 homeDirectory: /home/sam loginshell: /bin/bash uid: sam... (2 Replies)
Discussion started by: samgoober
2 Replies

4. Shell Programming and Scripting

Copy/print all lines between pattern is found in .log files

Hi, I have a folder with multiple (< 33) .log files. And I have to copy the lines between two patterns from all the .log files to a new file. (script file with a loop?) Thanks in advance. 1.log ... .. xx1> begin ... .. .. >>> Total: 2 Alarms .. .. (17 Replies)
Discussion started by: AK47
17 Replies

5. Shell Programming and Scripting

awk to print all lines after a pattern is found

Is there a way with aw to print all lines after a string is found There is a file like this ....... ........ 2012/19/11 :11.58 PM some data lne no date 2012/19/11 :11.59 PM some other data 2012/20/11 :12.00 AM some other data some line without dates some more lines without dates... (8 Replies)
Discussion started by: swayam123
8 Replies

6. UNIX for Dummies Questions & Answers

Grouping or appending the lines in a file through Unix

Hi, I am looking for a way to Group the Lines in a file.. Basically My file structure is something like this A 1 100 abc def A 1 200 abc def A 1 300 abc def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def A 1 100 abc def A 1 200 xyz def A 1 300 xyz def I need it as... (6 Replies)
Discussion started by: mkandula1983
6 Replies

7. Shell Programming and Scripting

Grouping or appending the lines in a file through Unix

Hi, I am looking for a way to Group the Lines in a file.. Basically My file structure is something like this A 1 100 abc def A 1 200 abc def A 1 300 abc def A 2 100 pqr def A 2 200 pqr def A 2 300 pqr def A 1 100 abc def A 1 200 xyz def A 1 300 xyz def I need it as... (1 Reply)
Discussion started by: mkandula1983
1 Replies

8. Shell Programming and Scripting

appending lines to a file dynamically

Hi all, I have a file with some number of lines. I need to add certain number of lines from another file which may vary according to the user's input and to it. eg code: I/P file 1 apps/file/xyz apps/file/abc apps/file/def file 2 progs/file/xyz ... (2 Replies)
Discussion started by: Ananthdoss
2 Replies

9. Shell Programming and Scripting

Delete a block of text delimited by blank lines when pattern is found

I have a file which contains blocks of text - each block is a multi-lines text delimited by blank lines eg. <blank line> several lines of text ... pattern found on this line several more lines of text ... <blank line> How do you delete the block of text (including the blank lines) when... (17 Replies)
Discussion started by: gleu
17 Replies

10. Shell Programming and Scripting

need help appending lines/combining lines within a file...

Is there a way to combine two lines onto a single line...append the following line onto the previous line? I have the following file that contains some blank lines and some lines I would like to append to the previous line... current file: checking dsk c19t2d6 checking dsk c19t2d7 ... (2 Replies)
Discussion started by: mr_manny
2 Replies
Login or Register to Ask a Question