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 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. |
There are lots of ways to kill this bird. The easiest is probably awk.
Code:
ldd cheezewiz | awk '/=>/{print $3}' Code:
ldd cheezewiz | sed -rn '/=>/ s/.*=> ([^ ]+) .*/\1/p' 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/ |
This is the most resilient method I've found:
Code:
ldd calcoo | sed 's/.*=> //' | awk '{ print $1 }' Code:
linux-vdso.so.1 (0x00007fff283bf000) |
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 }' |
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! |
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.
|
All times are GMT -5. The time now is 04:57 AM. |