LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-19-2007, 09:38 AM   #1
inonzi_prowler
LQ Newbie
 
Registered: Feb 2007
Location: London
Distribution: Kubuntu, Solaris
Posts: 4

Rep: Reputation: 0
Question sed display line after pattern match


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.
 
Old 02-19-2007, 09:44 AM   #2
inonzi_prowler
LQ Newbie
 
Registered: Feb 2007
Location: London
Distribution: Kubuntu, Solaris
Posts: 4

Original Poster
Rep: Reputation: 0
oh yeah the line <Owner> only appears once per file, but the pattern <standardPartyId> appears quite often (as you would have probably gathered).
 
Old 02-19-2007, 11:39 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Here is a really good SED tutorial.

I am rusty on SED, but I think you will use the command to read a new line, followed by print.

In the basic syntax, you are operating strictly on the line that has been read into the "pattern space"--without reading a new line, there is no way to print it.
 
Old 02-19-2007, 01:47 PM   #4
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,836

Rep: Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590Reputation: 590
how about printing the line number (season to taste):

Code:
line=`grep -n ^<Owner> file.xml | cut -f 1 -d :`
line=`expr $line + 1`
sed -n "$line"p 837.tmp
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
Vim - Pattern to match email address taylor_venable Linux - Software 2 01-31-2007 04:56 PM
Pattern match and counting script -->how to write ? froglinux LQ Suggestions & Feedback 4 06-11-2006 06:10 PM
how to use the sed w option to redirect pattern match to file nickleus Linux - General 11 04-18-2006 08:34 AM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM


All times are GMT -5. The time now is 04:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration