LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-30-2014, 04:11 PM   #1
pillows
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Sed Getting the Line After Regex


I am looking to grab the line after a matching regex in a file.

E.g. here is a file

>Title1
Information about title1
>Title2
Information about title2

I want to search '>Title1' and print the line below it!

Thanks!
 
Old 05-30-2014, 04:46 PM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
I put 'sed print line after pattern' in to Google and found this

http://www.theunixschool.com/2012/05...few-lines.html
 
Old 05-30-2014, 04:54 PM   #3
pillows
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I know you think I did not properly search the internet before posting. But I did, and the "N" thingy gave me weird errors which I should have mentioned. But I simply dealt with getting two lines instead of one so I went with the grep -A command.

Good resource you posted though I actually didn't see it since I was looking for "sed get/grab/print line after match/regex"
 
Old 05-30-2014, 05:27 PM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
Quote:
Originally Posted by pillows View Post
I know you think I did not properly search the internet before posting. But I did, and the "N" thingy gave me weird errors which I should have mentioned.
You should have kept reading it further. A few lines below the "N" thingy, it shows:


Code:
sed -n '/Title1/{n;p}' after.txt
 
  


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
sed regex one or none '?' casperdaghost Linux - Newbie 5 06-21-2012 10:44 AM
[SOLVED] sed edit the line above a regex expression corcodelagaze Programming 9 02-25-2012 09:52 AM
sed and regex help zski128 Programming 5 12-13-2011 11:30 AM
Help with sed regex homer_3 Linux - General 1 08-18-2009 02:57 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 06:10 AM


All times are GMT -5. The time now is 05:43 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration