Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 02-19-2007, 09:38 AM   #1
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:

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
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
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,147

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

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


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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:26 PM.

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