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. 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; Code:
perl -pi -e "s/$REGEX/$REPLACE/g" $FILE |
Quote:
Quote:
Code:
find . -iregex ".*\\.\\(m3u\\|xml\\|sfv\\)$" -type f -print Code:
Quote:
|
do it in one with perlpower ...
this searches for supplied file extensions, (like .c .pl) whatever (DO NOT include the * as in *.c) and substitues THIS for THAT with a .bak file. Code:
#! /usr/local/bin/perl -w |
All times are GMT -5. The time now is 09:59 AM. |