Tweeted twitter.com/#!/StackUnix/status/166302549606019073
2 added 25 characters in body
source | link

I'm trying to remove characters from a file name. files

ls

files

Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).log Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue

#ls
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).flac
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).log
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue

whatWhat I want for output

ls Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log:

script

#ls
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

script

#!/bin/bash
    SUFFIX="(AutoFLAC)"
    #search directory for file with a suffix of (AutoFLAC)
    for entry in *$SUFFIX*
     do
        #remove a leading space and (AutoFLAC) from the file name
        FILENAME=`echo $entry | sed 's/ (AutoFLAC)//'`
      echo "$entry"
      echo "$FILENAME"
        #change the old file name for the new file name
       mv  "$entry" "$FILENAME"
 done

done

ifIf I add -x it works

Mac-Attack:edit-file-names $ ./edit-file-names1.sh + SUFFIX='(AutoFLAC)' + for entry in '$SUFFIX' ++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).flac' ++ sed 's/ (AutoFLAC)//' + FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac + mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' + for entry in '$SUFFIX' ++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).log' ++ sed 's/ (AutoFLAC)//' + FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log + mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' Mac-Attack:edit-file-names $ ls Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac Peter, Paul & Mary - The Very Best of Peter-x, Paul and Maryit works.log

without the -x

Mac-Attack:edit-file-names $ ./edit-file-names1.sh 
+ SUFFIX='(AutoFLAC)'
+ for entry in '*$SUFFIX*'
++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).flac'
++ sed 's/ (AutoFLAC)//'
+ FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac'
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac
+ mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' 
'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac'
+ for entry in '*$SUFFIX*'
++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).log'
++ sed 's/ (AutoFLAC)//'
+ FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log'
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log
+ mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log'
Mac-Attack:edit-file-names $ ls
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

Mac-Attack:edit-file-names $ ./edit-file-names2.sh (AutoFLAC) (AutoFLAC) mv: rename (AutoFLAC) toWithout the (AutoFLAC)-x: No such file or directory

Mac-Attack:edit-file-names $ ./edit-file-names2.sh 
*(AutoFLAC)*
*(AutoFLAC)*
mv: rename *(AutoFLAC)* to *(AutoFLAC)*: No such file or directory

insightsInsights, thoughts?

much thanks for looking.

trying to remove characters from a file name. files

ls

Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).log Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue

what I want for output

ls Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

script

    #!/bin/bash
    SUFFIX="(AutoFLAC)"
    #search directory for file with a suffix of (AutoFLAC)
    for entry in *$SUFFIX*
     do
        #remove a leading space and (AutoFLAC) from the file name
        FILENAME=`echo $entry | sed 's/ (AutoFLAC)//'`
      echo "$entry"
      echo "$FILENAME"
        #change the old file name for the new file name
       mv  "$entry" "$FILENAME"

done

if I add -x it works

Mac-Attack:edit-file-names $ ./edit-file-names1.sh + SUFFIX='(AutoFLAC)' + for entry in '$SUFFIX' ++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).flac' ++ sed 's/ (AutoFLAC)//' + FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac + mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' + for entry in '$SUFFIX' ++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).log' ++ sed 's/ (AutoFLAC)//' + FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log + mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' Mac-Attack:edit-file-names $ ls Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

without the -x

Mac-Attack:edit-file-names $ ./edit-file-names2.sh (AutoFLAC) (AutoFLAC) mv: rename (AutoFLAC) to (AutoFLAC): No such file or directory

insights, thoughts?

much thanks for looking.

I'm trying to remove characters from a file name.

files

#ls
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).flac
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).log
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue

What I want for output:

#ls
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

script

#!/bin/bash
SUFFIX="(AutoFLAC)"
#search directory for file with a suffix of (AutoFLAC)
for entry in *$SUFFIX*
do
   #remove a leading space and (AutoFLAC) from the file name
   FILENAME=`echo $entry | sed 's/ (AutoFLAC)//'`
   echo "$entry"
   echo "$FILENAME"
   #change the old file name for the new file name
   mv  "$entry" "$FILENAME"
 done

If I add -x, it works.

Mac-Attack:edit-file-names $ ./edit-file-names1.sh 
+ SUFFIX='(AutoFLAC)'
+ for entry in '*$SUFFIX*'
++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).flac'
++ sed 's/ (AutoFLAC)//'
+ FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac'
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac
+ mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' 
'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac'
+ for entry in '*$SUFFIX*'
++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).log'
++ sed 's/ (AutoFLAC)//'
+ FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log'
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log
+ echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log'
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log
+ mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log'
Mac-Attack:edit-file-names $ ls
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac
Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

Without the -x:

Mac-Attack:edit-file-names $ ./edit-file-names2.sh 
*(AutoFLAC)*
*(AutoFLAC)*
mv: rename *(AutoFLAC)* to *(AutoFLAC)*: No such file or directory

Insights, thoughts?

1
source | link

bash script works with in debug only

trying to remove characters from a file name. files

ls

Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFlac).log Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue

what I want for output

ls Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

script

    #!/bin/bash
    SUFFIX="(AutoFLAC)"
    #search directory for file with a suffix of (AutoFLAC)
    for entry in *$SUFFIX*
     do
        #remove a leading space and (AutoFLAC) from the file name
        FILENAME=`echo $entry | sed 's/ (AutoFLAC)//'`
      echo "$entry"
      echo "$FILENAME"
        #change the old file name for the new file name
       mv  "$entry" "$FILENAME"

done

if I add -x it works

Mac-Attack:edit-file-names $ ./edit-file-names1.sh + SUFFIX='(AutoFLAC)' + for entry in '$SUFFIX' ++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).flac' ++ sed 's/ (AutoFLAC)//' + FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac + mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).flac' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac' + for entry in '$SUFFIX' ++ echo Peter, Paul '&' Mary - The Very Best of Peter, Paul and Mary '(AutoFLAC).log' ++ sed 's/ (AutoFLAC)//' + FILENAME='Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log + echo 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log + mv 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary (AutoFLAC).log' 'Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log' Mac-Attack:edit-file-names $ ls Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.cue Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.flac Peter, Paul & Mary - The Very Best of Peter, Paul and Mary.log

without the -x

Mac-Attack:edit-file-names $ ./edit-file-names2.sh (AutoFLAC) (AutoFLAC) mv: rename (AutoFLAC) to (AutoFLAC): No such file or directory

insights, thoughts?

much thanks for looking.