Shell sed regex syntax... help to remove parenthesis

This should be simple but I just cannot get the syntax correct to remove the closing parenthesis.

I have a collection of files named as follows:
'EMFD Plane Crash Oct 26 2011 (39).JPG'​

The intervening spaces are a problem and also the parenthesis wrapping the serial number.
This is the sed construct that I'm trying to use:

sed '/ Plane Crash Oct 26 2011 (/s//-/'

. . .and effectively produces this result:
'EMFD-39).JPG'
I need to strip-out the closing parenthesis. Can anyone with more regex experience than me suggest a solution? :confused:
 
If you are just trying to remove certain characters, tr(1) is easier:
Code:
% echo 'EMFD Plane Crash Oct 26 2011 (39).JPG' | tr -d '() '
EMFDPlaneCrashOct26201139.JPG

The problem with using regular expressions here is that they have to match what is in the string. Not just the characters, but the positions. Also, the regexes used by sed(1) are ancient and weak. Perl's are much more powerful, and can do this more easily. Although still not as easily as tr(1), if you just need to remove characters.
 
I was just coming back with my solution:

FYI, here is the whole renaming scenario (just a simple csh script):

# ls [I]dir-containing-files[/I] | rename.sh

Code:
/* *** rename.sh *** */

while read FILE;
do
   newname=`echo ${FILE} | sed '/ Plane Crash Oct 26 2011 (/s//-/; s/)//'`
   mv "${FILE}" "${newname}"
done
exit(0)
Now outputs EMFD-39.JPG

I was leaving out the semicolon . . .duh :rolleyes:

. . .and BTW, it looks like your suggestion to use tr gets it done with one less line of code. . . .umm, I think not, as with sed, the mv instruction is still needed.
 
Maybe a combination of tr and awk?

Code:
echo 'EMFD Plane Crash Oct 26 2011 (39).JPG' | awk '{ print $1,"-",$NF}' | tr -d '() '
EMFD-39.JPG

Reards
Markus
 
Back
Top