The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk print the next line on the current line ajp7701 Shell Programming and Scripting 5 05-25-2009 12:17 PM
print any required line by its line no using awk and its NR variable RahulJoshi Shell Programming and Scripting 2 09-07-2008 02:35 AM
print line whatever line i want in a file... there any way kittusri9 Shell Programming and Scripting 1 05-15-2008 12:37 PM
extract lines with a given list of identifiers mskcc Shell Programming and Scripting 3 04-13-2006 11:15 PM
Print file line by line handak9 Shell Programming and Scripting 2 10-20-2005 08:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-05-2009
parshant_bvcoe parshant_bvcoe is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 21
Print Selection of Line between two Identifiers.

I have a following containing DATA in the following format:

[START1]
DATA....------
---------------
--------------
[END1]
DATA.....------
--------------------
------------------
[START1]
DATA....------
---------------
--------------
[END1]


I want to extract the selective DATA in between identifiers [START1] and [END1] including starting identifier i.e, [START1] as depicted below:

[START1]
DATA....------
---------------
--------------
[START1]
DATA....------
---------------
--------------

Please help me with this.Thanks!
  #2 (permalink)  
Old 01-05-2009
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Registered User
  
 

Join Date: Jul 2008
Location: Phoenix, Arizona
Posts: 669
Try this:
Code:
# cat somefile | awk -F '[START1]' 'BEGIN{RS="[END1]"; OFS="\n"; ORS=""} {print $2}'
  #3 (permalink)  
Old 01-06-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,047
Code:
sed -n '/START1/,/END1/p' a.txt | sed '/END1/d'
Code:
awk '/START1/{flag=1}
/END1/{flag=0}
flag==1 {print}' a.txt
  #4 (permalink)  
Old 01-06-2009
frostmourn frostmourn is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 8
Code:
sed -n '/\[START1\]/{:a;N;/\[END1\]/!ba;s/\n[^\n]\+$//;p}' filename
  #5 (permalink)  
Old 01-07-2009
parshant_bvcoe parshant_bvcoe is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 21
Thanks Friends !!!
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 On



All times are GMT -4. The time now is 12:28 PM.


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

Content Relevant URLs by vBSEO 3.2.0