dr_strangelove |
06-23-2010 05:37 PM |
REGEX from array, returns no matches.
Hello,
I'm attempting to use REGEX to isolate media (video and audio) essence that relate to alias/reference Quicktime movies. The Quicktime movie filename (excluding ".mov" can always be found in the media-essence filename.
Stages of my process are: - I cache the contents of a text file into an array ($file). This text file/array contains a list of Quicktime movies and media essence. Essence for each Quicktime movie is contained in this text file. An example text file is below:
Code:
MOVIE1.mov
media.dir/MOVIE1.m2v
media.dir/MOVIE1.wav
media.dir/MOVIE1_1.wav
media.dir/MOVIE1_2.wav
media.dir/MOVIE1_3.wav
MOVIE2.mov
media.dir/MOVIE2.m2v
media.dir/MOVIE2.wav
media.dir/MOVIE2_1.wav
media.dir/MOVIE2_2.wav
media.dir/MOVIE2_3.wav
MOVIE3.mov
media.dir/MOVIE3.m2v
media.dir/MOVIE3.wav
media.dir/MOVIE3_1.wav
media.dir/MOVIE3_2.wav
media.dir/MOVIE3_3.wav
- I isolate which items in the list are Quicktime movies (simply REGEX matching ".mov" and cache these in another array for later use in the script.
- Each item within the Quicktime-movie array ($mov_array) is used as search criteria when searching the remainder of the file list.
- I plan on using all items which match the Quicktime mov filename (pre ".mov") to generate ffmpeg tasks.
My problem is that the following statement
Code:
if [[ $essence =~ $id ]]
returns no results.
If I manually intervene and state that
Code:
#id="SOMETHINGOROTHER"
then I get results.
Extracted code is below:
Code:
#!/bin/bash
#This script loops through a text file and creates an ffmpeg string to wrap this essence into a single container.
number_mov=0
array=()
mov_array=${#array[*]}
regex1="mov"
topdir="/Users/Dev/1107613"
subdir="/media.dir/"
cd $topdir
IFS='
'
file=( $( < MOVIES.txt ) ) # Here we grab the contents of the text file within the folder
for (( i = 0 ; i < ${#file[@]} ; i++ )) # Here we loop through its contents and check for the presence of each line
do
a=${file[$i]}
if [[ $a =~ $regex1 ]]; then # If we match regex1 (normally, is it a mov?) then ...
mov_array=(${mov_array[@]} "$a") # ... add this to the array of movs
number_mov=$((number_mov+1))
fi
done
for mov in ${mov_array[@]} # Loop through our MOV array ...
do
id=$(echo $mov|sed 's/.mov//g') # ... remove the file extension, remember, only movs should be in this array!
echo 'Media ID -' $id
for essence in ${file[@]} # Loop through our MOV array ...
do
#id="MOVIE1"
echo "Checking"
echo $id
echo $essence
if [[ $essence =~ $id ]]
then
echo "Match"
else
echo "Unlucky"
fi
echo
done
done
Many thanks in advance and apologies if I'm missing something bleedingly obvious.
dr_strangelove
NB* This script is being developed on Mac OS X 10.5.8, for eventual deployment on Linux version 2.6.27.7-9-pae (geeko@buildhost) (gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) )
|