#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    How to remove a section of text in all audio filenames in a folder?


    how to remove a section of text in all audio filenames in a folder?

    i made a slight mistake on a conversion script and ended up with this



    img716.imageshack.us[forwardslashhere]img716[forwardslashhere]8973[forwardslashhere]acabi.png


    sorry but a picture is clearer than text here



    how can i remove the section ".flac}.shn.shn} " in all the files from the commandline?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,481
    Rep Power
    1752
    Not tested, so be warned!

    Code:
    for fn in $(ls -1 *.flac}.shn.shn}*)
    do
      new=$(echo $fn | sed 's/.flac}.shn.shn}//')
      mv $fb $new
    done
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    thank you for prompt reply

    can't be far off it gives me this


    for fn in $(ls -1 *.flac}.shn.shn}*) > do > new=$(echo $fn | sed 's/.flac}.shn.shn}//') > mv $fb $new > done mv: missing destination file operand after `08.' Try `mv --help' for more information. mv: missing destination file operand after `Instante.shn' Try `mv --help' for more information.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Try this and obviously like simonJM said it hasn't been tested:
    Code:
    for fn in `ls *.flac}.shn.shn}*`
    do
      new_fn=`echo $fn | sed 's/.flac}.shn.shn}//'`
      echo "Current name: $fn"
      echo "New     name: $new_fn"
      mv $fn $new_fn
    done

    Comments on this post

    • SimonJM agrees : Gah, I typoed $fn to $fb!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    thank you spacebar

    direct hit [ had tried to think of something in the way of fn_new]
    but not enough to make it work: this is perfect thanx

    ~/Desktop/Arrigo/5$ for fn in `ls *.flac}.shn.shn}*` > do > new_fn=`echo $fn | sed 's/.flac}.shn.shn}//'` > echo "Current name: $fn" > echo "New name: $new_fn" > mv $fn $new_fn > done Current name: 08.Instante.flac}.shn.shn}.shn New name: 08.Instante.shn



    i forgot to mention something tho and that is that some of the files have gaps in them so those will not work with this....

    07. Clara Crocodilo.flac}.shn.shn.shn
    if i use this first

    Code:
    for f in *.shn;  do rename 's/\ * /_/g'   "$f"  "${f%.*shn}.shn" ;done


    all gaps are gone and then i can use the script; but then my cuefile no longer functions so i need to keep the original gaps in the songs titles and remove .flac}.shn.shn


    anyone can see a clever way to add that functionality to the script? thanx in advance shan

  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Location
    spaceBAR Central
    Posts
    229
    Rep Power
    42
    Umm, I don't think that is the problem, the file name you denote as not being listed doesn't have a '}' after the 2nd "shn", look at my tests below for the 3 file names and the 'ls' command that will list them:

    Code:
    07. Clara Crocodilo.flac}.shn.shn}.shn
    08.Instante.flac}.shn.shn}.shn
    07. Clara Crocodilo.flac}.shn.shn.shn
    
    $ ls *.flac}.shn.shn}* *.flac}.shn.shn.*
    07. Clara Crocodilo.flac}.shn.shn.shn
    07. Clara Crocodilo.flac}.shn.shn}.shn
    08.Instante.flac}.shn.shn}.shn
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    actually it does i simply did not copy it right

    it should have read


    07. Clara Crocodilo.flac}.shn.shn}.shn

    sorry i am really bad at copying code


    your script works a charm when there are no gaps but on a different folder with same mistake this is what i get


    shantiq@shantiq-00000000000000000000000:/media/777a9ed8-803f-42d0-af07-c03b98c26ba2/Music/Jean Martinon (1989) Debussy Complete Orchestral Works III/Untitled Folder$ for fn in `ls *.m4a}*` > do > new_fn=`echo $fn | sed 's/.m4a}//'` > echo "Current name: $fn" > echo "New name: $new_fn" > mv $fn $new_fn > done Current name: 01 New name: 01 mv: cannot stat `01': No such file or directory Current name: - New name: - mv: cannot stat `-': No such file or directory Current name: Doctor New name: Doctor mv: cannot stat `Doctor': No such file or directory Current name: Gradus New name: Gradus mv: cannot stat `Gradus': No such file or directory Current name: and New name: and mv: cannot stat `and': No such file or directory Current name: Parnassum.m4a}.shn New name: Parnassum.shn mv: cannot stat `Parnassum.m4a}.shn': No such file or directory shantiq@shantiq-00000000000000000000000:/media/777a9ed8-803f-42d0-af07-c03b98c26ba2/Music/Jean Martinon (1989) Debussy Complete Orchestral Works III/Untitled Folder$

    the original file is named and this time i make sure

    01 - Doctor Gradus and Parnassum.m4a}.shn

    so there seems to be a gap issue

    no big deal.... if you see it please tell me but no sweat...

    thanx for your input


    shan
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,481
    Rep Power
    1752
    Slightly different tack ..

    Code:
    ls -1 *.flac}.shn.shn}* > /tmp/shn.lst && while read fn
    do
    new=$(echo $fn | sed 's/.flac}.shn.shn}//')
    echo Renaming "$fn" to "$new"
    mv "$fn" "$new"
    done < /tmp/shn.lst
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by SimonJM
    Slightly different tack ..

    Code:
    ls -1 *.flac}.shn.shn}* > /tmp/shn.lst && while read fn
    do
    new=$(echo $fn | sed 's/.flac}.shn.shn}//')
    echo Renaming "$fn" to "$new"
    mv "$fn" "$new"
    done < /tmp/shn.lst

    thank you Simon .... all gaps kept... excellent i am trying to learn from you guys


    Code:
     01 - Doctor Gradus and Parnassum.m4a}.shn
    [my other "mistake" in another folder] is now
    Code:
    01 - Doctor Gradus and Parnassum.shn

    was also wondering [and will have a tinker] if there might be a route with rename [in Ubuntu and no doubt elsewhere... on the net under rename by Larry Wall]

    see if that might also work

    RENAME(1) Perl Programmers Reference Guide RENAME(1) NAME rename - renames multiple files SYNOPSIS rename [ -v ] [ -n ] [ -f ] perlexpr [ files ] DESCRIPTION "rename" renames the filenames supplied according to the rule specified as the first argument. The perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input. For example, to rename all files matching "*.bak" to strip the extension, you might say rename 's/\.bak$//' *.bak To translate uppercase names to lower, you'd use rename 'y/A-Z/a-z/' *
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,481
    Rep Power
    1752
    Good luck.

    I tend to try and keep with 'standard' *nix tools as much as I can (experience of having to do things in HP-UX, Solaris, SuSE Linux, etc., etc.)
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0
    ok and yes it works fine

    rename is on my Ubuntu by default and can be found easily on the net under rename Larry Wall it is a Perl script


    in this case
    Code:
    rename 's/.flac}.shn.shn}//'  *
    worked fine too

    One more tool I will keep with your scripts

    Last edited by shantiq; September 5th, 2012 at 02:24 PM. Reason: correction

IMN logo majestic logo threadwatch logo seochat tools logo