Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-03-2008
Registered User
 

Join Date: Dec 2008
Posts: 7
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..
Sponsored Links
  #2 (permalink)  
Old 12-03-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669

Code:
cat test | awk -F 'START_LABEL' 'BEGIN{RS="END_LABEL"; OFS="\n"; ORS=""} {print $2}'

  #3 (permalink)  
Old 12-03-2008
Registered User
 

Join Date: Dec 2008
Posts: 7
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 (permalink)  
Old 12-03-2008
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 4,943
Try this:


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

Regards
  #5 (permalink)  
Old 12-03-2008
Registered User
 

Join Date: Dec 2008
Posts: 7
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 (permalink)  
Old 12-03-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,194
as always on Solaris, use 'nawk' instead of 'awk'.
  #7 (permalink)  
Old 12-03-2008
Registered User
 

Join Date: Sep 2008
Posts: 205
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove matching lines with list of strings Nanu_Manju Shell Programming and Scripting 6 10-29-2008 05:11 AM
using AWK see the upper lines and lower lines of the strings?? thepurple Shell Programming and Scripting 3 10-07-2008 11:24 AM
Copying common lines to a new file khestoi UNIX for Dummies Questions & Answers 3 09-12-2008 06:31 PM
To find all common lines from 'n' no. of files The Observer Shell Programming and Scripting 11 06-16-2008 03:22 PM
how to take out common of two lines in a file jam_ali49 UNIX for Advanced & Expert Users 6 11-23-2007 04:48 AM



All times are GMT -4. The time now is 03:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0