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
Extracting text out of specific lines krabu Shell Programming and Scripting 3 04-16-2009 06:04 PM
extracting text and reusing the text to rename file JohnDS UNIX for Dummies Questions & Answers 7 02-05-2009 03:55 AM
Copying Text between two unique text patterns spindoctor UNIX for Dummies Questions & Answers 3 01-16-2009 03:42 AM
extracting unique lines from text file soliberus Shell Programming and Scripting 3 08-22-2008 10:18 AM
Extracting records with unique fields from a fixed width txt file sitney Shell Programming and Scripting 8 02-10-2008 03:18 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-17-2009
Grizzly Grizzly is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 28
Extracting Text Between Two Unique Lines

Hi all! Im trying to extract a portion of text from a file and put it into a new file. I need all the lines between <Placement> and </Placement> including the Placemark lines themselves. Is there a way to extract all instances of these and not just the first one found? I've tried using sed and awk but I cant seem to get the format right. Say the original file is called file.kml and the new one newfile.kml. If it helps its on a Solaris box.

Original File
Code:
...
<Placemark>
...
...
...
</Placemark>
...
...
<Placemark>
...
...
...
</Placemark>
...
New File
Code:
<Placemark>
...
...
...
</Placemark>
<Placemark>
...
...
...
</Placemark>
Thanks!
  #2 (permalink)  
Old 09-18-2009
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
Hi,

Try this.

Code:
 awk '/<Placemark>/,/<\/Placemark>/ {print}' file
Regards,

Ranjith
  #3 (permalink)  
Old 09-18-2009
skmdu skmdu is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 102
Code:
sed  -n '/<Placemark>/,/<\/Placemark>/p' file


---------- Post updated at 12:18 AM ---------- Previous update was at 12:18 AM ----------

Code:
sed -n '
/^<Place/!b
:loop
$!{
N
/<\/Place/!b loop
}
p' place
  #4 (permalink)  
Old 09-18-2009
rdcwayx rdcwayx is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 204
Quote:
Originally Posted by ranjithpr View Post
Hi,

Try this.

Code:
 awk '/<Placemark>/,/<\/Placemark>/ {print}' file
Regards,

Ranjith


awk '/<Placemark>/,/<\/Placemark>/' file
  #5 (permalink)  
Old 09-18-2009
Grizzly Grizzly is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 28
Quote:
Originally Posted by rdcwayx View Post


awk '/<Placemark>/,/<\/Placemark>/' file
So file is the file its reading or the file its writing the output too?

####
I figured it out.

Last edited by Grizzly; 09-18-2009 at 05:30 AM..
Reply

Bookmarks

Tags
awk, extract, sed, solaris

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 04:33 PM.


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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0