LinuxQuestions.org
Review your favorite Linux distribution.
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-30-2008, 09:09 AM   #1
xberetta21
LQ Newbie
 
Registered: Jan 2008
Posts: 9

Rep: Reputation: 0
Help with Rename / Removing ( ) !!!!!!!!!!!!!!!1


Here is the problem I am using this code to remove ( ) parenthesis from directory names in which the script is in the same location as the files.

for i in *\(*\)*; do j=`echo $i |sed -e 's/[()]//g'`; mv "$i" "$j"; done


My problem is that the files that need to be changed are on the 2nd level, for example I am running this code in a folder that has alot of Subject Numbers like 001 002 003 etc and dont want to have to copy the script into each subfoler. In these folders contain the directories that need to have the parenthesis ( ) removed. This shoudl be a simple addition or modifcation to the code like a while loop to move up a directory but I cant seem to figure it out. Coudl someone please help me? Any input is appreciated and I thank you in advance.

I tried somethign like this:


while read SUBJ #still a line in the control file
do
cd SUBJ
for i in *\(*\)*; do j=`echo $i |sed -e 's/[()]//g'`; mv "$i" "$j"; done
done
cd ..


But I didnt not get any results. Thanks again!

Last edited by xberetta21; 01-30-2008 at 09:11 AM.
 
Old 01-30-2008, 09:31 AM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,232

Rep: Reputation: 299Reputation: 299Reputation: 299
You could make the script call itself:

Code:
for f in *
do
   if [ -d "$f" ]
   then
      cd "$f"
      Call script here
      cd ..
   fi

   do renaming here

done
Here is an example of a script win2lin that takes out spaces and other characters:
Code:
#!/bin/bash

 function basic {
 for i in *
 do
     if [ -d "$i" ]
     then
         cd "$i"
         win2lin #name of this script. Must be in PATH or full path to script must be given.
         cd ..
     fi
     tempa=$(echo "$i" | sed 's/ /_/g' | sed 's/_-_/-/g' |  sed 's/\ -\ /-/g' | sed 's/__/_/g' \
     | sed "s#'##g" | sed "s#;##g" | sed "s#,##g")
     [[ "$i" != "$tempa" ]] && mv -v "$i" "$tempa"
 done
 }

 function cmd {
 for i in "$@"
 do
     tempa=$(echo "$i"  | sed 's/ /_/g' | sed 's/_-_/-/g' |  sed 's/\ -\ /-/g' | sed 's/__/_/g' \
     | sed "s#'##g" | sed "s#;##g" | sed "s#,##g")
     [[ "$i" != "$tempa" ]] && mv -v "$i" "$tempa"
     [[ ! -d "$tempa" ]] && break
     cd "$tempa"
     win2lin #name of this script. Must be in PATH or full path to script must be given.
     cd ..
 done
 }

 [[ "$@" != "" ]] && cmd "$@"
 [[ "$@" == "" ]] && basic
 
Old 01-30-2008, 03:40 PM   #3
xberetta21
LQ Newbie
 
Registered: Jan 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks!

Thanks alot dude. This forum is the best! Quick responses and knowledable peopel!
 
  


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
Removing Gnome apps without removing gnome desktop? 449 Linux - Newbie 1 01-29-2008 11:40 PM
removing text shadows in kde; removing taskbar color gradient webazoid Linux - Software 1 04-11-2006 03:56 AM
Removing files wihtout removing containing Direcotry caps_phisto Linux - General 2 10-07-2004 09:16 AM
Rename my pc ? Tanc Linux - Newbie 6 09-13-2003 09:28 AM
How to rename a file? juanb Linux - General 4 03-19-2003 12:20 PM


All times are GMT -5. The time now is 12:34 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration