[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

how to match parenthesis in sed



Hello,

I am renaming files by removing parentheses from them. These are image
files which were sorted in Windows (by placing them in the desired order
and then by renaming them in batch mode in Windows explorer -- couldn't
do this in Linux).

Here is an example:
20030113_Lohri_ (107).jpg   -> is to be named as:
20030113_Lohri_ 107.jpg

This I can accomplish by:
$> nn=`echo "20030113_Lohri_ (107).jpg" | tr -d "()"`; echo $nn

which spits out the modified name (in variable nn) and the output is:
20030113_Lohri_ 107.jpg

However, I also want to remove that space preceding the opening
parenthesis in the input filename. I am trying to do this via sed,
something like (the following is one long line):
$> nn=`echo "20030113_Lohri_ (107).jpg" | sed -e
s/\(.*\)\.[Jj][Pp][Gg]/\1.jpg/`;

However, this is not working. The above should give just the basename
and then I add an extension of ".jpg" to it. I am guessing the
parentheses in the input filename is causing the problem. How do I match
 parenthesis in sed then?

thanks,
->HS



Reply to: