sed or grep or perl combine two lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed or grep or perl combine two lines
# 1  
Old 06-27-2003
sed or grep or perl combine two lines

how do i search for the phrase "expected" on line one and
"received" on line two. (there is a newline in between the two)
I would like to know if/how this can be done in perl and/or
grep and/or sed
# 2  
Old 06-27-2003
It might help others here if you explain what you're trying to do... there's always many ways to do one task...
# 3  
Old 06-27-2003
i have a large file with embedded sequential lines containing the word "expected" or "received":
for example
line 1 some data
line 2 some more data
line 3 123expected456
line 4 123received456
line 5 more data
line 6 more data
line 7 123expected
line 8 456 expected
line 9 777 received
I want to capture lines 3 and 4, lines 8 and 9
(i. e., 2 lines in a row, the first containing expected,
the second containing received)
# 4  
Old 06-27-2003
Have you tried the awk '/start/,/ending/' option?

awk /"expected"/,/"received"/ myfile

You would have to know positively that you would have expected and then received...any chance of "expected" without the next line having the "received" and you would get all lines in between

(my test file)
expected 5000
received 10000
so what will we do next time we expected something
should not see this line
expected 4000
received 200
okay all done


You would have to know that you would not get an error like with this test file.

Otherwise, you could look this thread and modify it just a little.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Combine multiple unique lines from event log text file into one line, use PERL or AWK?

I can't decide if I should use AWK or PERL after pouring over these forums for hours today I decided I'd post something and see if I couldn't get some advice. I've got a text file full of hundreds of events in this format: Record Number : 1 Records in Seq : ... (3 Replies)
Discussion started by: Mayday22
3 Replies

3. Shell Programming and Scripting

grep/sed to remove lines in file

Hi, I have a file with values, file1: BELL-1180-1180-81|577:1017| BELL-1180-1180-81|jm10i-auto-stub1/577:102| BELL-1180-1180-81|jm10i-auto-stub1/577:101| BELL-1180-1180-81|jm10i-auto-stub1/577:1700| BELL-1180-1180-81|jm10i-auto-stub1/577:1699| I need to remove the lines which has... (9 Replies)
Discussion started by: giri_luck
9 Replies

4. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

5. Shell Programming and Scripting

Sed grep the first matched lines

Hi I have a myfile.txt contains the following: CONTEXT { AAAAA } ... CONTEXT { BBBBB } I want to extract the lines in between CONTEXT { ... }, one by one. Hence I wrote a command like the following, sed -n '/^CONTENT/,/^}/ { w a.txt }' myfile.txt The problem with this... (5 Replies)
Discussion started by: hezjing
5 Replies

6. Shell Programming and Scripting

combine two perl lines into a single perl command

Hi Everyone, i have a string 00:44:40 so: $tmp=~ s/://gi; $tmp=~s/({2})({2})({2})/$1*3600+$2*60+$3/e; the output is 2680. Any way to combine this two lines into a single line? Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

7. Shell Programming and Scripting

Like grep -v for a string over 2 lines? Sed?

Hi, I have a log file that I need to monitor as it's being written to, and I want to exclude certain strings from the output. At the moment I'm using ... tail -f LogFileName_`date +%d`.log | egrep -v "First String To Exclude | 2nd string | 3rd string" ...which works OK - but now I need to... (1 Reply)
Discussion started by: jake657
1 Replies

8. Shell Programming and Scripting

[Help] PERL Script - grep multiple lines

Hi Gurus, I need some help with the "grep" command or whatever command that you think suitable for me. I'm about to write a perl script to extract a report from the system and submit it to the end users. The input for the script will consist of 3 element. 1) Generation ID 2) Month 3) Year... (6 Replies)
Discussion started by: miskin
6 Replies

9. Shell Programming and Scripting

sed, grep, cut or combine?

I am a beginner at shell scripting, actually i am working on my first script right now. Anyway i have searched the world how to grep two letters from each word (it will always just be two words). For example: Example Blablabla I want my script to cut out Ex (from the first word) and Bl... (4 Replies)
Discussion started by: maskot
4 Replies

10. UNIX for Dummies Questions & Answers

SImple HELP! how to combine two lines together using sed or awk..

hi..im new to UNIX... ok i have this information in the normal shell... there are 2 lines display like this: h@hotmail.com k@hotmail.com i want it to display like this with a space betweem them h@hotmail.com k@hotmail.com the information is stored in a text file.... anyone... (10 Replies)
Discussion started by: forevercalz
10 Replies
Login or Register to Ask a Question