LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-04-2013, 01:29 PM   #1
luw
LQ Newbie
 
Registered: Jan 2007
Location: greater nyc area
Distribution: ubuntu10 LTS, opensolaris 5.11, tinycore 3.x
Posts: 19

Rep: Reputation: 0
sed problems. possibly delimiter related


I am creating a script that pulls out certain path+files that get dumped from ldd. so as an example, say the program is named "cheezewiz".

Code:
$ ldd cheezewiz
	libQtGui.so.4 => /usr/lib/x86_64-linux-gnu/libQtGui.so.4 (0x00007fcca6c37000)
	libQtDBus.so.4 => /usr/lib/x86_64-linux-gnu/libQtDBus.so.4 (0x00007fcca69ba000)
	libQtXml.so.4 => /usr/lib/x86_64-linux-gnu/libQtXml.so.4 (0x00007fcca6777000)
	libQtSql.so.4 => /usr/lib/x86_64-linux-gnu/libQtSql.so.4 (0x00007fcca6537000)
	libQtCore.so.4 => /usr/lib/x86_64-linux-gnu/libQtCore.so.4 (0x00007fcca6065000)
What is to be pulled out is the path and file from each line, and erase the rest. (1st line example "/usr/lib/x86_64-linux-gnu/libQtGui.so.4")

I'm guessing a proper way to do this would use the "=> " as the first search point and the " (0" as the end. However I'm not sure how to extract this, nor what option would be best in sed. The main problem for me is I'm not sure if the => are special chars that need a "\" or what to do because the things that are searched for contain "/".

Does anyone have any tips or suggestions for how to approach this? I'd really apprecheate any response.
 
Old 06-04-2013, 01:44 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,848

Rep: Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012
There are lots of ways to kill this bird. The easiest is probably awk.

Code:
ldd cheezewiz | awk '/=>/{print $3}'
But if you really want to use sed, here are a couple of versions that should work too]

Code:
ldd cheezewiz | sed -rn '/=>/ s/.*=> ([^ ]+) .*/\1/p'
ldd cheezewiz | sed -rn '/=>/ s/(^.*=> | [(].*$)//gp'
By the way, sed's substitution delimiter can be any ascii character, not just '/'. It will use whatever comes directly after the 's', so just use something that doesn't appear in the expression itself. And no, '=' and '>' are not regex special.

Here are a few useful sed references:
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt
http://www.catonmat.net/series/sed-one-liners-explained

=====
Here are a few useful awk references:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/series/awk-one-liners-explained

=====
Here are a few regular expressions tutorials:
http://mywiki.wooledge.org/RegularExpression
http://www.grymoire.com/Unix/Regular.html
http://www.regular-expressions.info/
 
Old 06-04-2013, 02:32 PM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1292Reputation: 1292Reputation: 1292Reputation: 1292Reputation: 1292Reputation: 1292Reputation: 1292Reputation: 1292Reputation: 1292
This is the most resilient method I've found:

Code:
ldd calcoo | sed 's/.*=> //' | awk '{ print $1 }'
It passes things like:

Code:
	linux-vdso.so.1 (0x00007fff283bf000)
	libgtk-x11-2.0.so.0 => /usr/lib64/libgtk-x11-2.0.so.0 (0x00007f7b1e140000)
	libgdk-x11-2.0.so.0 => /usr/lib64/libgdk-x11-2.0.so.0 (0x00007f7b1de8e000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f7b184ef000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f7b1e78e000)
	libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007f7b182d8000)
 
Old 06-04-2013, 04:39 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,848

Rep: Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012
Actually, I'd say the second sed command I posted is probably the most reliable. It simply removes everything before and after the desired string, matching them with clearly defined regexes. And all in a single process.

If it's a bit difficult to comprehend, it can also be written this way, with two separate substitutions:
Code:
ldd cheezewiz | sed -n '/=>/ { s/^.*=> // ; s/ [(].*$// ; p }'
 
Old 06-08-2013, 02:01 AM   #5
luw
LQ Newbie
 
Registered: Jan 2007
Location: greater nyc area
Distribution: ubuntu10 LTS, opensolaris 5.11, tinycore 3.x
Posts: 19

Original Poster
Rep: Reputation: 0
Thank you David the H. and H_TeXMeX_H, both work great. As for the links, it seems everytime I need to use sed for something like this it ends up getting figured out, however the very next time I need to use it again, little or nothing from the past can help with a new problem.

I'm checking out the sourceforge grabbag now. Best regards and thanks again for your help!
 
Old 06-09-2013, 06:01 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,848

Rep: Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012Reputation: 2012
Yeah, it does take time and effort to gain experience with the tools you use. I know that I had some hair-pulling times myself (still do, occasionally). Just keep plugging away, and it'll eventually get easier.
 
  


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 delimiter kankan55 Linux - Newbie 6 02-21-2013 09:27 AM
[SOLVED] AWK / SED - Parsing a CSV file with comma delimiter, and some extra needs. PenguinJr Programming 8 05-24-2011 07:28 PM
sed : how to use delimiter Ashok_mittal Linux - Newbie 2 12-17-2008 07:41 AM
Sound Problems (cd player, flash, gaim, possibly related issues) mcmillan Linux - General 8 01-03-2006 11:56 PM
sed with delimiter, bourne uribo Programming 17 04-23-2003 02:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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