different take on common ?: search for two strings and remove lines between them


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting different take on common ?: search for two strings and remove lines between them
# 1  
Old 12-03-2008
different take on common ?: search for two strings and remove lines between them and

Thank you for assisting,

I've got a partial solution just needs a tweak.

Code:
Hulk-BASH$ cat somefile.txt
oh there is some stuff here
some more stuff here
START_LABEL
stuff I want
more stuff I want
END_LABEL
other stuff here too
and even more stuff here too
Hulk-BASH$

Hulk-BASH$ sed -n '/^START_LABEL/,/^END_LABEL/p' somefile.txt
START_LABEL
stuff I want
more stuff I want
END_LABEL
Hulk-BASH$

As you can see it's editing properly but I need the output to have the "LABELS" themselves removed so it looks like:

stuff I want
more stuff I want


Thanks for your help

L.

Last edited by laser; 12-03-2008 at 04:35 PM..
# 2  
Old 12-03-2008
Code:
cat test | awk -F 'START_LABEL' 'BEGIN{RS="END_LABEL"; OFS="\n"; ORS=""} {print $2}'

# 3  
Old 12-03-2008
Thank you Ikon, but I received this:

Code:
Hulk-BASH$ cat somefile.txt | awk -F 'START_LABEL' 'BEGIN{RS="END_LABEL"; OFS="\n"; ORS=""} {print $2}'
awk: syntax error near line 1
awk: bailing out near line 1
Hulk-BASH$

thx
# 4  
Old 12-03-2008
Try this:

Code:
awk '/^START_LABEL/{p=1;next}/^END_LABEL/{exit}p' file

Regards
# 5  
Old 12-03-2008
Wow I wonder what is up, still same errors, I'm using Solaris
Thx Franklin

Code:
Hulk-BASH$ awk '/^START_LABEL/{p=1;next}/^END_LABEL/{exit}p' somefile.txt
awk: syntax error near line 1
awk: bailing out near line 1
Hulk-BASH$

# 6  
Old 12-03-2008
as always on Solaris, use 'nawk' instead of 'awk'.
# 7  
Old 12-03-2008
Hi,

sed is fine, simply add some characters, e.g.:

Code:
sed -n '/^START_LABEL/,/^END_LABEL/{/LABEL$/!p}' somefile

Which means: of all the files between the LABEL print only line not
matching LABEL at the end.

HTH Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove lines containing 2 or more duplicate strings

Within my text file i have several thousand lines of text with some lines containing duplicate strings/words. I would like to entirely remove those lines which contain the duplicate strings. Eg; One and a Two Unix.com is the Best This as a Line Line Example duplicate sentence with the word... (22 Replies)
Discussion started by: martinsmith
22 Replies

2. UNIX for Dummies Questions & Answers

Search a file for certain strings and add them to the end of certain lines

I have a log file which lists groups and users in the following format GROUP1 user1 user2 user3 GROUP2 user4 user5 user6 GROUP3 user7 user8 I need to change the format to: user1|GROUP1 user2|GROUP1 user3|GROUP1 user4|GROUP2 (3 Replies)
Discussion started by: Angela S
3 Replies

3. Shell Programming and Scripting

How to search multiple patterns and remove lines from a file?

Hi, I have a file content as below. Table : PAYR Displayed fields: 15 of 15 Fixed columns: 4 List width 0999... (4 Replies)
Discussion started by: shirdi
4 Replies

4. Shell Programming and Scripting

Search and remove the lines

Hallo Team, Hope you are having a wonderful Friday. Here goes i am searching for a pattern and after finding the lines which contain this pattern i want to remove/delete them. This is my code: grep Originating BW*2013*|grep -v "ACCOUNT NOT FOUND"|grep -v "Unknown called number"|grep -v... (2 Replies)
Discussion started by: kekanap
2 Replies

5. Shell Programming and Scripting

Need the script to remove common strings,tags etc

I have a file say "example.xml" and the contents of this example.xml are <project name="platform/packages/wallpapers/Basic" path="packages/wallpapers/Basic" revision="225e410f054c4ad5c828b0fec9be1b47c4376711"/> <project name="platform/packages/wallpapers/Galaxy4"... (3 Replies)
Discussion started by: acdc
3 Replies

6. Shell Programming and Scripting

Compare one files with strings from another + remove lines

Have two files and want to compare the content of file1 with file2. When matched remove the line. awk 'NR==FNR {b; next} !(b in $0)' file1 file2file1 1. if match 2. removefile2 1. this line has to be removed if match 2. this line has a match, remove 3. this line has no match, no removingThe... (3 Replies)
Discussion started by: sdf
3 Replies

7. Shell Programming and Scripting

How to remove lines containing strings

Hi Guys, I need some script in removing lines containing strings like ",, ," and "rows". Retain only numbers as the output. See below for the input and output file. INPUT FILE: 9817 9832 6285 6312 6313 6318 ,, , 6329 7078 7098 7130 7959 7983 (7 Replies)
Discussion started by: pinpe
7 Replies

8. Shell Programming and Scripting

awk how to search strings within a file from two different lines

Hi, i would really appreciate any help anyone can give with the following info. Thanks in advance. I need to run a search on a file that contains thousands of trades, each trade is added into the file in blocks of 25 lines. i know the search has to take place between a time stamp specified... (4 Replies)
Discussion started by: sp3arsy
4 Replies

9. Shell Programming and Scripting

Search and Remove Lines within File

Hello, I've searched through the scripting section but could not find what I need. I need to search for empty sections within a file and remove them. Here is an example file: Title 123 A B C D E Title 098 Title 567 Z Y (4 Replies)
Discussion started by: leepet01
4 Replies

10. Shell Programming and Scripting

Remove matching lines with list of strings

Hi, HP-UX gxxxxxxxc B.11.23 U ia64 3717505098 unlimited-user license I have a file with below pipe separated field values: xxx|xxx|abcd|xxx|xxx|xx xxx|xxx|abcd#123|xxx|xxx|xx xxx|xxx|abcd#345|xxx|xxx|xx xxx|xxx|pqrs|xxx|xxx|xx xxx|xxx|pqrs#123|xxx|xxx|xx The third field has values like... (6 Replies)
Discussion started by: Nanu_Manju
6 Replies
Login or Register to Ask a Question