Register
It is currently Tue Jul 22, 2014 12:50 pm

sed display line after string match?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Feb 19, 2007 9:51 am   

Joined: Mon Feb 19, 2007 9:48 am
Posts: 2
hello all.

so i'm sending some text (xml) to sed and I have a particular string that I can match.

Thing is, I need the line after the string to be displayed.

text looks like this:

Quote:
<versionEffectiveDate>2006-10-27</versionEffectiveDate>
<Counterparty>
<standardPartyId>0141747</standardPartyId>
</Counterparty>
<Owner>
<standardPartyId>7066589</standardPartyId>
</Owner>


I need the line that comes after the string <Owner> (i.e. the line with 7066589 in it.

I've tried this:

cat file.xml | sed -n -e '/<Owner>/n'

but I get nothing returned. I need to do this on a whole bunch of files.

Many thanks in advance for any replies


Top
 Profile  
 PostPosted: Mon Feb 19, 2007 9:52 am   

Joined: Mon Feb 19, 2007 9:48 am
Posts: 2
oh yeah the line <Owner> only appears once per file, but the pattern <standardPartyId> appears quite often (as you would have probably gathered).


Top
 Profile  
 PostPosted: Mon Feb 19, 2007 7:11 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
I saved your test data.... surprisingly enough as test.data ;)

Code:
[crouse@localhost Scripts]$ grep -A 1 "<Owner" test.data | grep -v "<Owner"
<standardPartyId>7066589</standardPartyId>
[crouse@localhost Scripts]$


oh.... and in case you actually WANTED to use sed.... i looked it up (yeah...i can't remember all the sed stuff in my head lol)

Code:
[crouse@localhost Scripts]$ cat test.data | sed -n '/<Owner/{n;p;}'
<standardPartyId>7066589</standardPartyId>
[crouse@localhost Scripts]$ 


;) HTH's


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP