hello,
this will rename anything with an extention of tmp to what ever it is w/o the .tmp extention - not sure why the *.* is not taking hold...
Code:#!/bin/bash for i in *.* do name=$(echo $i|sed 's/\.tmp$//')
i have the variable $filename which i'd like to strip of it's extension. i mean for example in perl i'd simply do
and that'd leave me with the name minus the extension. Has anyone any ideas about how i can do this with a bash script?Code:$filename =~ s/(.+?)\..*/$1/;
thanks,
-Sean
hello,
this will rename anything with an extention of tmp to what ever it is w/o the .tmp extention - not sure why the *.* is not taking hold...
Code:#!/bin/bash for i in *.* do name=$(echo $i|sed 's/\.tmp$//')
Works for me
Just a quick extension to the question...i only need to strip the types .ram and .rm, short of repeating the RE on the next line is there a way i can do this?
my weak attempt didn't seem to fly...
Code:name=$(echo $i|sed 's/\.["ram"|"rm"]$//')
Try || or /
ahh, never mind. Through use of consumate .'s (well one...) i managed.
thanks for the help, pbharrisCode:name=$(echo $i|sed 's/\..*$//')
- Sean
perl can be used from the command line too:
foo=$(echo $i | perl -e 's/foo/bar/g'![]()
You can also do this without any external program, using plain bash:
Code:#!/bin/bash tmp1="file1.ram" tmp2="file2.rm" shopt -s extglob echo ${tmp1%.@(ram|rm)} echo ${tmp2%.@(ram|rm)}
[quote author=Hko link=board=9;threadid=7681;start=0#msg70211 date=1062779536]You can also do this without any external program, using plain bash:[/quote]
very cool, i always thought calling sed seemed unneeded for something so simple, but it was usually quick scripts i'd never use again so i never really looked. thanks for the tip!
Bookmarks