LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   HELP! Script to RENAME/REMOVE ( ) From File NAMES!! (http://www.linuxquestions.org/questions/linux-newbie-8/help-script-to-rename-remove-from-file-names-617151/)

xberetta21 01-29-2008 09:51 AM

HELP! Script to RENAME/REMOVE ( ) From File NAMES!!
 
Hello, I am workign with linux and am looking for a script/command that will remove ( ) parenthesis from a series of file names in a given directory. I have been given various pieces of code but they either done work or return the error "Badly places ( )" which is redundant becuase I know they are badly placed. If ANYONE has a solution your input woudl be greatly appreciated.

Thanks in advance.

MensaWater 01-29-2008 10:08 AM

Code:

for FILE in `ls |grep \(`
do NEWFILE=`echo $FILE |sed -e s/\(*// |sed -e s/\)//`
  echo $NEWFILE
  mv $FILE $NEWFILE
done


nfisk 01-29-2008 10:16 AM

How about just a one-liner:

Code:

for i in *\(*\)*; do j=`echo $i |sed -e 's/[()]//g'`; mv "$i" "$j"; done
Works for me, but you may want to try it in some harmless directory first, before you unleash it on your actual data.

xberetta21 01-29-2008 10:53 AM

Thank You Both Of You.
 
I tried NFISK approach first simply becuase it was shorter, and it worked like a charm. I have been working on this on and off for a week. I appreciate BOTH your help and thanks again!!!

MensaWater 01-29-2008 01:10 PM

Technically Nfisk's wasn't really a one liner except he separated the commands by semicolon. One could do the same with the one I posted (and leave out the echo which I hadn't meant to include - it was there in my testing).

Anyway glad you got it solved.


All times are GMT -5. The time now is 12:00 PM.