Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm looking for a way to iterate through a list of files that have blank spaces in their names. I haven't had much luck with the find command so far:
Code:
for i in `find . -iname "*.mp3"`
do
echo $i
done
since it splits the filenames by whitespaces. I found a successful workaround which involves renaming the files by replacing spaces with underscores, then reverting the operation, but this is far from elegant. Could someone provide a better solution?
Thank you both -- unfortunately neither solution was quite what I'm looking for.
Trying the quoting trick gives me one long string with all the file names separated with line breaks, which echoes to the console quite nicely but still does not iterate correctly -- it goes through the for loop exactly once, regardless of the amount of files found. For X matches in the find command I need exactly X iterations of the for loop.
What I'm looking for is a way to iterate through all mp3 files in a directory, then perform some tagging on each one individually. This gets quite complex as I have to formulate the tag data from the file name itself, then call id3v2 with the appropriate switches and tag strings. So far haven't managed to get find working the way I want it to, and -exec {} hasn't really helped me either yet.
Last edited by sir_woland; 10-04-2007 at 04:23 PM.
Reason: typo
Change the default field separator to newline - then your original should work.
Pays to save and restore the IFS value, but that's just personal preference.
Yes! Changing the IFS was precisely the correct thing to do, and running the script in a subshell lets me use the new IFS value only for the duration of the script. Works perfectly, thank you!
The reason -exec didn't fly is that the tagging command I need to run for each and every file is of the form:
Code:
id3v2 -T tracknum -t "trackname" file_to_process
where tracknum and trackname are strings cut from the file name and piped through tr and sed. Too much for my inept skills!
I will do it like this:
You can use the -print0 option to use a null instead of a carriage return. The list can be fed to xargs with the -0 option.
If the source or filenames is another command you can pipe the output through "| tr '\n' '\000' |"
example:
find . -iname "*.mp3" -print0 | xargs -0 mpg2ogg
When I use K3B to make a backup of a directory, I'll save the .k3b file and unzip it and use sed to obtain the filenames backed up. Then I can pipe the output through "| tr '\n' '\000' | xargs -0 rm -v" to remove the files backed up.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.