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.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-21-2008
space_tux space_tux is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Sed Question

I'm new at shell scripting and wanna ask how can i use sed command for deleting data between two xml tag such as

Now: </outbox>asd<outbox>

After sed command : </outbox><outbox>



Ps: i used => sed -e 's/<\/outbox>[a-z]*<outbox>//g' filein > fileout
  #2 (permalink)  
Old 11-21-2008
Christoph Spohr Christoph Spohr is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 205
Hi,

one way is:

Code:
sed "s/\(<[^>]*>\)[^<]*\(<[^>]*>\)/\1\2/" file
This will match a save the content between the first pair of "<>", match everything between them and then match and safe the content between the next pair of "<>" and replace it by the safed patterns.

HTH Chris
  #3 (permalink)  
Old 11-21-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,309
Or shorter:

Code:
sed 's/\(.*>\).*\(<.*\)/\1\2/'
  #4 (permalink)  
Old 11-21-2008
space_tux space_tux is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Thanks for your answers;
I tried both codes but didint work i'm using korn shell does it effect anything?
  #5 (permalink)  
Old 11-21-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,309
It should work with the example you have given, but I think it's more complex than that with your file.
  #6 (permalink)  
Old 11-24-2008
space_tux space_tux is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Quote:
Originally Posted by Franklin52 View Post
It should work with the example you have given, but I think it's more complex than that with your file.
Franklin I guess i located the problem its ;because of my XML's format...

Example updated :
<book>
<thriller>abc</thriller>
<comedy>vfg</comedy>
</book>


I want to delete everything between <book> and </book> ; " .* " doesnt work for new lines ; its only usefull for one lined xml tags.How can i bypass the new line (enter).

Ps:the updated example is the real format of my XML
  #7 (permalink)  
Old 11-24-2008
space_tux space_tux is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Franklin52 thanks a lot for the answers and thanks for your patience have a good day

Ps: if i'm not too pushy can you please explain the awk command
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

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

Content Relevant URLs by vBSEO 3.2.0