LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 01: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, 02:12 PM   #2
ruario
Senior Member
 
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,184

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

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


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


All times are GMT -5. The time now is 05:24 PM.

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