How to remove a section of text in all audio filenames in a folder?
Discuss How to remove a section of text in all audio filenames in a folder? in the UNIX Help forum on Dev Shed. How to remove a section of text in all audio filenames in a folder? UNIX Help forum discussing the Unix Operating System and all variants including Irix, Solarix, and AIX. Unix was designed as a true multi-user operating system.
Posts: 2,108
Time spent in forums: 1 Month 1 Week 1 Day 4 h 16 m 23 sec
Reputation Power: 1485
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
Posts: 9
Time spent in forums: 4 h 26 m 40 sec
Reputation Power: 0
thank you for prompt reply
can't be far off it gives me this
Quote:
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.
Posts: 188
Time spent in forums: 2 Days 9 h 9 m 4 sec
Reputation Power: 41
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
Posts: 9
Time spent in forums: 4 h 26 m 40 sec
Reputation 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
Quote:
~/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....
Quote:
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
Posts: 188
Time spent in forums: 2 Days 9 h 9 m 4 sec
Reputation Power: 41
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
Posts: 9
Time spent in forums: 4 h 26 m 40 sec
Reputation Power: 0
actually it does i simply did not copy it right
it should have read
Quote:
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
Quote:
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
Quote:
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...
Posts: 9
Time spent in forums: 4 h 26 m 40 sec
Reputation Power: 0
Quote:
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
Quote:
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/' *