LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 01-17-2011, 12:54 PM   #1
noony123
Member
 
Registered: Oct 2010
Posts: 167

Rep: Reputation: 0
sed, print only the searched string !


Hi all.

Like grep -o option which extracts the interesting value from the input file. Is there any way sed can also extract the interesting string from the line instead of print whole lines ?

Like for example, i have following 3 lines

asdada dog12 asdad ad asda d
asdadadadadog12asdadad
dog12asdadadasdad ad ad

Now i just want to extract dog12 using sed, pls tell me
 
Old 01-17-2011, 01:12 PM   #2
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,557

Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
If I understand your request correctly I think you want something like:
Code:
sed -n "s,.*\(dog12\).*,\1,p"
 
Old 01-17-2011, 06:09 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Addendum - if you use -r as well you don't require escaping of brackets
 
  


Reply



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
how do i replace a text string in a file with a random string? (with sed etc) steve51184 Linux - Software 16 09-02-2010 11:05 AM
sed: how to change MAC address string with sed cold Linux - Software 5 08-02-2010 07:43 AM
search string in text and print string wolfipa Linux - Software 4 09-17-2009 08:50 AM
Trying to change String using sed with a string \/home\/user\/Desktop icecoolcorey Programming 10 06-12-2008 11:32 PM
sed: print section of file from string to end of file samyboy Linux - Newbie 4 02-26-2008 07:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:03 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
Open Source Consulting | Domain Registration