Click to See Complete Forum and Search --> : please, sed help
soleblazer
03-28-2001, 11:40 PM
Hi, I need to use sed to stip off the extension of files. I have this:
ls | sed 's/....$//'
This works fine if the filenames have exactly 3 character extension. How can I get it to always trim everything off including the "."
I tried this:
ls | sed 's/,..*$ but this didnt work.
Anyone got any ideas?
Thanks!!
jemfinch
03-29-2001, 01:37 AM
s/(.*)\..*/\1/
I haven't tried it with sed, but it'll work with perl and python.
Jeremy
soleblazer
03-29-2001, 10:00 AM
nah, appreciate the perl help, but it doesn't work as far as syntax goes for sed. anyone know what rel. I can use for this?]
Thanks!
jemfinch
03-29-2001, 01:20 PM
I don't waste my time with sed because sticking to perl and python ensures that I only have to learn one regexp flavor.
In sed, you have to escape parentheses, because sed it st00pid.
You should use perl -pe instead of sed.
Or, when python 2.1 comes out, use my little filt.py script, which is even cooler than perl -pe.
But definitely don't use sed.
You still insist on using sed? Against my will? Against better judgement?
oh well.
sed 's/\(.*\)\..*/\1/'
Now please, go learn the very standard perl/python regexp flavor so I don't have to do this again...
Jeremy
YaRness
03-29-2001, 01:48 PM
if you can see past the bad attitude, jemfinch is right: sed really does kinda suck. for most things you might wanna do i think you'll find perl ( or i GUESS python :P or anything else that might be similar ) to be worth taking the time to learn. it'll give you more capabilities, and if you learn perl regexps (and perl syntax of course), perl can be used for lots more uses than sed.
of course if yer not that interested in programming, then i guess anything quick'n'dirty will work :/
soleblazer
03-29-2001, 01:52 PM
Cool.
Any books suggested to start learning Perl? I have never really programmed before and am learning shell scripting fairly well.
Thanks.
:rolleyes:
jemfinch
03-29-2001, 02:58 PM
Originally posted by soleblazer:
Any books suggested to start learning Perl? I have never really programmed before and am learning shell scripting fairly well.
Hell no. Learn python instead. You can find the necessary tutorial at http://www.python.org/doc/current/tut/tut.html and the necessary library reference at http://www.python.org/doc/current/lib/lib.html .
Jeremy