Visit The New, Modern Unix Linux Community


print certain pattern from 2 lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print certain pattern from 2 lines
# 1  
print certain pattern from 2 lines

i have 2 lines comming out of a script o/p.below the line.

2008-10-14 05:47:05,551 [Thread-6] INFO - LPBatch: [null, 1-GH32X, null, DC:Tue Oct 14 10:12:37 UTC 2008, null, null, Mon Oct 13 05:00:00 CDT 2008, Mon Oct 13 10:00:00 UTC 2008, Tue Oct 14 04:45:00 CDT 2008, Tue Oct 14 09:45:00 UTC 2008, CC, AMR, 94]

2008-10-14 05:47:05,575 [Thread-6] INFO - Number of Intervals Not Inserted: 1 / 95

--------------------------------------------------------------------------

How to print the below o/p from the above 2 lines:

1-GH32X|CC|AMR|Number of Intervals Not Inserted: 1 / 95

------------------------------------------------------------------------

like wise my final o/p varies depending on the above 2 lines but it has to print in this fashion.plz help me in this
# 2  
Hammer & Screwdriver How are two lines linked/connected

Are the two lines always consecutive?
Are there only two lines, and always two lines?

It would probably be helpful to see a slightly larger sample file - perhaps maybe three pairs of data records? This makes it easier to write a command to extract appropriate data.
# 3  
Actually according to my script 3 lines will be outputed whenever a pattern is matched

Pattern line
next immediate 2 lines
--------------------------------------------------------------------------

Also the next 2 immediate line varies with each pattern found

below few examples:

2008-10-14 05:47:05,551 [Thread-6] ERROR - CleanLPDataMessage: Missing Intervals: 1
2008-10-14 05:47:05,551 [Thread-6] INFO - LPBatch: [null, 1-GH32X, null, DC:Tue Oct 14 10:12:37 UTC 2008, null, null, Mon Oct 13 05:00:00 CDT 2008, Mon Oct 13 10:00:00 UTC 2008, Tue Oct 14 04:45:00 CDT 2008, Tue Oct 14 09:45:00 UTC 2008, CC, AMR, 94]
2008-10-14 05:47:05,575 [Thread-6] INFO - Number of Intervals Not Inserted: 1 / 95
*********************************************

2008-10-14 05:50:54,072 [Thread-6] ERROR - CleanLPDataMessage: Missing Intervals: 1
2008-10-14 05:50:54,072 [Thread-6] INFO - LPBatch: [null, 1-150KP1, null, DC:Tue Oct 14 10:16:52 UTC 2008, null, null, Mon Oct 13 04:45:00 CDT 2008, Mon Oct 13 09:45:00 UTC 2008, Tue Oct 14 04:45:00 CDT 2008, Tue Oct 14 09:45:00 UTC 2008, CC, AMR, 95]
2008-10-14 05:50:54,101 [Thread-6] INFO - Number of Intervals Not Inserted: 1 / 96
****************************************************

2008-10-14 05:55:41,604 [Thread-6] ERROR - CleanLPDataMessage: Missing Intervals: 1
2008-10-14 05:55:41,604 [Thread-6] INFO - LPBatch: [null, 1-VWEMR, null, DC:Tue Oct 14 10:22:06 UTC 2008, null, null, Mon Oct 13 04:30:00 CDT 2008, Mon Oct 13 09:30:00 UTC 2008, Tue Oct 14 05:00:00 CDT 2008, Tue Oct 14 10:00:00 UTC 2008, CC, AMR, 97]
2008-10-14 05:55:41,634 [Thread-6] INFO - Number of Intervals Not Inserted: 1 / 98

*********************************************


So i wanted the o/p in the below fashion

1-GH32X|CC|AMR|Number of Intervals Not Inserted: 1 / 95
1-150KP1|CC|AMR|Number of Intervals Not Inserted: 1 / 96
1-VWEMR|CC|AMR|Number of Intervals Not Inserted: 1 / 98

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #780
Difficulty: Easy
Bill Gates was born in Seattle, Washington, on October 28, 1945.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print lines after matching two pattern

would like to print everything after matching two patterns AAA and BBB. output : CCC ZZZ sample data : AAA BBB CCC ZZZ (4 Replies)
Discussion started by: jhonnyrip
4 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

3. AIX

Grep a pattern and print following n lines

Hi all, I am struck with the below requirement. I need to grep a particular pattern in a file and then print next n lines of it for further processing. I have used the below code grep -A 3 "pattern" filename But it is throwing error as below. grep: illegal option -- A Can... (14 Replies)
Discussion started by: ssk250
14 Replies

4. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

5. Shell Programming and Scripting

How to print the lines between two pattern in a file?

file like: services: XXXXXXXX: XXXXXXX: XXXXXXXXX1 XXXXX XXXXXXXXX DDDDDDDDDDD BBBBB: version: 11.2.0.4 services: YYYYYYYYYY XXXXXXXXXX: XXXXXXXXX XXXXXXXX XXXXXXXXX... (5 Replies)
Discussion started by: netbanker
5 Replies

6. Shell Programming and Scripting

Print lines before after pattern meacted

Hi All, Am trying to print pervious lines of the pattern matched, I was able to print pattern matched and the required data but don't know how to get the pervious line. ifconfig -a | grep 10.118.67.33 | sed -e 's/^]*//' -e 's/]*$//' | awk '{FS=" "; print $6}' output I... (2 Replies)
Discussion started by: Optimus81
2 Replies

7. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

8. Shell Programming and Scripting

Print lines before and after pattern match

I am using Solaris, I want to print 3 lines before pattern match pattern 5 lines after pattern match Pattern is abcd to be searched in a.txt. Looking for the solution in sed/awk/perl. Thanks .. Input File a.txt: ================= 1 2 3 abcd 4 5 6 7 8 (7 Replies)
Discussion started by: manuswami
7 Replies

9. Shell Programming and Scripting

print lines up to pattern excluding pattern

11 22 33 44 55 66 77 When pattern 55 is met, print upto it, so output is 11 22 33 44 (1 Reply)
Discussion started by: anilcliff
1 Replies

10. Shell Programming and Scripting

Print the above and below lines for the grep pattern.

Hi, i would like to get the above and below lines of the grep pattern . For ex : file as below: chk1- aaaa 1-Nov chk2 -aaaa ########## chk1-bbbbbb 1-Nov chk2-bbbbbb ######### my search pattern is date : 1-Nov i need the o/p as below chk1- aaaa 1-Nov (6 Replies)
Discussion started by: expert
6 Replies

Featured Tech Videos