I am new to linux and/or scripting, so bear with me. I want a script which can get the files for a Linux directory. here what I tried for getting the filename.
for NAME in $(ls -1 *.wav /some/path | cut -d "/" -f3 | cut -d "-" -f1-5)
if the filename contains -IN or -OUT then they will be sox -m and after that mv to another directory but if the some other files then it will be just mv
for the reference, filenames be like
1030-04-06-2015-1433414216.wav
1030-04-06-2015-1433414318.wav
1030-04-06-2015-1433414440.wav
1043-21-05-2015-1432207256.wav
1043-21-05-2015-1432207457.wav
1046-20-05-2015-1432137944.wav
1046-20-05-2015-1432138015.wav
1046-20-05-2015-1432138704.wav
1431709157.93900.0-in.wav
1431709157.93900.0-out.wav
1431709157.93900.1-in.wav
1431709157.93900.1-out.wav
1431710008.94059.0-in.wav
1431710008.94059.0-out.wav
1431710008.94059.1-in.wav
1431710008.94059.1-out.wav
1431710008.94059.1.wav
1431710008.94059.2.wav
1431713190.94698.2-in.wav
1431713190.94698.2-out.wav
1431713190.94698.2.wav
1431721107.96010.0-in.wav
1431721107.96010.0-out.wav
1431721107.96010.1.wav
This should work:
Explanation:
"${file##*\/}"
is the string left by cutting*/
from$file
i.e the basename (filename)."${BASH_REMATCH[2]}"
is the second captured group from the pattern matching done by[[ $file =~ $regex ]]
i.e-in
or-out
"${BASH_REMATCH[3]}"
is the third captured group i.e.wav
."${filename%.*}"
is the string left by cutting.*
from$file
i.e filename without.wav
Resources you should check on: