LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-29-2008, 09:51 AM   #1
xberetta21
LQ Newbie
 
Registered: Jan 2008
Posts: 9

Rep: Reputation: 0
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.
 
Old 01-29-2008, 10:08 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Code:
for FILE in `ls |grep \(`
do NEWFILE=`echo $FILE |sed -e s/\(*// |sed -e s/\)//`
   echo $NEWFILE
   mv $FILE $NEWFILE
done
 
Old 01-29-2008, 10:16 AM   #3
nfisk
Member
 
Registered: Jul 2002
Location: Stockholm, Sweden
Distribution: Kubuntu, Fedora
Posts: 45

Rep: Reputation: 15
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.
 
Old 01-29-2008, 10:53 AM   #4
xberetta21
LQ Newbie
 
Registered: Jan 2008
Posts: 9

Original Poster
Rep: Reputation: 0
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!!!

Last edited by xberetta21; 01-29-2008 at 11:13 AM.
 
Old 01-29-2008, 01:10 PM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to rename file while copying - and remove special characters corporal79 Linux - General 3 10-11-2007 04:16 PM
Desktop icons of file systems - remove/rename? lefty.crupps MEPIS 2 06-06-2005 08:36 PM
rename file names with " ? characters fishbonz Linux - Newbie 2 05-31-2005 11:20 AM
File rename script jjwl89 Linux - General 1 03-14-2005 06:28 PM
remove * from file nameS zchoyt Linux - Newbie 1 02-13-2005 04:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration