Results 1 to 2 of 2
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 ...
- 03-29-2007 #1Just Joined!
- Join Date
- Mar 2007
- Posts
- 5
Testing if a file has a particular extension
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.
The Bash script should accept command line arguments with several extensions. scriptname.sh --ext *.m3u,*.xml,*.sfv.Code:find . -depth \(-name ’*.sfv’ -o -name ‘*.m3u’\) -type f -print
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;
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.Code:perl -pi -e "s/$REGEX/$REPLACE/g" $FILE
- 03-30-2007 #2Just Joined!
- Join Date
- Mar 2007
- Posts
- 5
Here's an approach that worked for me.
find ./ -regex ".*\(m3u\|sfv\|xml\)$" -type f -print


Reply With Quote