I am hoping for some ideas on testing if a file has an extension passed as a command line argument. The challenge involves testing multiple extensions in a script. For example, if the file is a m3u, sfv, or xml file then cat it and perform some command. I don’t think the following works for me; for FILE in *. m3u *. sfv *. xml.
I chose FIND for added portability and additional options. I have gotten this far.
Code:
find . -depth \(-name ’*.sfv’ -o -name ‘*.m3u’\) -type f -print
The Bash script should accept command line arguments with several extensions. scriptname.sh --ext *.m3u,*.xml,*.sfv.
The script performs recursive searches and finds files with these extensions. Hard coding the extension would be the easy part. After finding the said files, it iterates (while loop) through an external file with regular expression patterns. Then it performs replacements inside the file and output a new file. This Perl line helps me achieve this goal;
Code:
perl -pi -e "s/$REGEX/$REPLACE/g" $FILE
This portion script complements the main purpose of renaming files. So the script rename a bunch of files (right now it consist of mp3 files) then renames the files in the playlist (*.m3u) and sfv (*.sfv) files. I may also need to grep for lines with mp3 line, because the script should perform the replacements on the mp3 pointers since these were the files renamed.