LinuxQuestions.org
Help answer threads with 0 replies.
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
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,934
Blog Entries: 5

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
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
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,934
Blog Entries: 5

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 07:34 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration