Gus Wirth wrote:
> I have a bunch of lines similar to the following generated from an rpm
> spec file using grep:
>
> %{_libdir}/wine/odbc32.dll.so
>
> I want to trim off the front part %{_libdir}/wine/ and the back part
> .dll.so leaving only the base name of the file. All the lines have
> exactly the same front and back parts so I can do an exact match. I'm
> trying to figure out if I can do the removal in one shot or if I need
> two passes to do this, but right now about the only thing I know about
> sed is that it exists and is used for stuff like this. Trying to use GNU
> info pages is a recipe for headaches. Is there a simple reference for
> sed anywhere other than the O'Reilly sed & awk book? Or, since this is a
> one-off project, can someone give me some hints?
sed 's/^.*wine\/\(.*\)\.dll.so/\1/' test.dat
perl -lpe '[EMAIL PROTECTED]/(.*)[EMAIL PROTECTED]@' test.dat
If you have any non-matching lines, the perl one might be
perl -lne 'print if [EMAIL PROTECTED]/(.*)[EMAIL PROTECTED]@' test.dat
The awk&sed book is good, but googling for sed one-liners is also
educational.
Likewise for perl one-liners. Perl was intentionally made to emulate sed
for simple changes, and if you like (or are more familiar with) its
regex syntax than sed, it might be preferable.
Sed really shines though, where you need to match multiple things and
possibly perform varying actions on various matches, or process lines
before/after the match.
Actually, you can even handle your example with bash .. if you'd only
read the manual! ;-) :-)
Check under the *Parameter Expansion* section the use of
${parameter#word}
${parameter##word}
${parameter%word}
${parameter%%word}
But I would only use this for lightweight duty. Sed or perl (or most any
scripting language) would be better for your example.
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list