sed print all lines between second and third identical lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed print all lines between second and third identical lines
# 1  
Old 11-24-2012
sed print all lines between second and third identical lines

I am trying to extract a table of data (mysql query output) from a log file. I need to print everything below the header and not past the end of the table. I have spent many hours searching with little progress. I am matching the regexp
Code:
+-\{99\}

with no problem. I just can't figure out how to print just between the second and third matches. I would like to do this with sed, because I am already useing sed a couple of other places in the script.
Thanks for your help.
# 2  
Old 11-24-2012
Please post a representative sample of the input and the corresponding desired output.
Also, do not try to oversimplify things; else you might end up with a long thread before getting any proper solution.
# 3  
Old 11-24-2012
Otherwise try:
Code:
awk '/\+-{99}\+/{p++; next}p==2' file

--
With GNU awk < 4.0 Try awk --posix
or try:
Code:
awk '/\+-+\+/{p++; next}p==2' file

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 11-27-2012
Quote:
Originally Posted by Scrutinizer
Otherwise try:
Code:
awk '/\+-{99}\+/{p++; next}p==2' file

--
With GNU awk < 4.0 Try awk --posix
or try:
Code:
awk '/\+-+\+/{p++; next}p==2' file

The last line worked just fine. My awk version is mawk 1.3.3 Nov 1996. Please explain the the search pattern used here. I have just about worn the print off the pages of my O'Reilly book.
# 5  
Old 11-27-2012
Hi the first line does not work with mawk since mawk does not support the braced repetition operator {..}. The last line uses the simple repetition operator + which means 1 or more. So this extended regular expression means a plus-sign \+ followed by one or more minus-signs -+ followed by a plus-sign \+..
# 6  
Old 11-27-2012
Thanks again; much appreciated.
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 - If field value of consecutive records are the identical print portion of lines

I have some data that looks like this: PXD= ZW< 1,6 QR> QRJ== 1,2(5) QR> QRJ== 4,1(2) QR> QRJ== 4,2 QRB= QRB 4,2 QWM QWM 6,2 R<C ZW< 11,2 R<H= R<J= 6,1 R>H XZJ= 1,2(2) R>H XZJ= 2,6(2) R>H XZJ= 4,1(2) R>H XZJ= 6,2 RDP RDP 1,2 What I would like to do is if fields $1 and $2 are... (5 Replies)
Discussion started by: jvoot
5 Replies

2. UNIX for Beginners Questions & Answers

How to delete identical lines while leaving one undeleted?

Hi, I have a file as follows. file1 Hello Hi His Hi Hi Hungry hi so I want to delete identical lines while leaving one of them undeleted. So desired output will be Hello Hi (2 Replies)
Discussion started by: beginner_99
2 Replies

3. Shell Programming and Scripting

Use sed to print first n lines and last n lines of an output.

Use sed to print first n lines and last n lines of an output. For example: n=10 Can it be done? Thanks. (7 Replies)
Discussion started by: carloszhang
7 Replies

4. UNIX for Dummies Questions & Answers

more than 10 identical lines

I have a file that looks like this 10 user1s, 5 user2s and 10 users3. 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.1 user1 10.10.1.2 user2 10.10.1.2 user2 10.10.1.2 user2... (7 Replies)
Discussion started by: lawsongeek
7 Replies

5. Shell Programming and Scripting

print lines AFTER lines cointaining a regexp (or print every first and fourth line)

Hi all, This should be very easy but I can't figure it out... I have a file that looks like this: @SRR057408.1 FW8Y5CK02R652T length=34 AGCAGTGGTATCAACGCAGAGTAAGCAGTGGTAT +SRR057408.1 FW8Y5CK02R652T length=34 FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8 @SRR057408.2 FW8Y5CK02TBMHV length=52... (1 Reply)
Discussion started by: kmkocot
1 Replies

6. Solaris

sed command to print lines after expression

Hi guys. I need a sed command to print like 10 lines after a regular expression is found in the log. Can anyone help me out. Thanks ---------- Post updated at 10:52 AM ---------- Previous update was at 10:34 AM ---------- never mind. I just did the search bewteen two expressions. (1 Reply)
Discussion started by: jamie_collins
1 Replies

7. Shell Programming and Scripting

read file-print lines in sed

Hello! Im trying to read file contents. Then, print out every line that has "/bens/here" in the file that was read. cat /my/file.now | sed '/bens/here/p' I keep getting the error asking if I need to predeclare sed? What does predeclaring sed mean? Thanks! Ben (2 Replies)
Discussion started by: bigben1220
2 Replies

8. Shell Programming and Scripting

Sed syntax to print lines that do not end with )}

I must admit I am relativly new to sed, and I am trying to make a simple sed query to search log files and return multiple variables from multiple logs. So far I have had success, but one problem remains: Alot of lines in the log files wrap onto multiple lines and are not being returned as... (2 Replies)
Discussion started by: demanche
2 Replies

9. Shell Programming and Scripting

Ignore identical lines

Hello Experts, I have two files called "old" and "new". My old file contains 10 lines and my new file contains 10 + "n" lines. The first field in both these files contain ID. I sort these two files on ID. I am interested in only the lines that are in the new file and not in old. I tried... (4 Replies)
Discussion started by: forumthreads
4 Replies

10. Shell Programming and Scripting

replace 2 identical strings on different lines

I am looking to replace two or more strings on different lines using sed, but not with the same variable. IE # cat xxx.file <abc> abc def ghi abc def ghi abc def ghi currently I can only change each line with the same pattern: # sed -e '/<abc>/!s/abc\(.*\)/jkl mno/' xxx.file abc jkl mno... (3 Replies)
Discussion started by: prkfriryce
3 Replies
Login or Register to Ask a Question