command line list all files in directory & all combinations
I have a folder containing 7 mp4 videos. I found a script that is able to combine two video's together in one video (split screen)
Now, I need to have a script that is able to return me all possibilities of video comparisons.
Example: my video directory (ex: only three files) VID1.mp4 VID2.mp4 VID3.mp4
and what I need is a script that returns this:
VID1.mp4 VID2.mp4 VID1.mp4 VID3.mp4 VID2.mp4 VID1.mp4 VID2.mp4 VID3.mp4 VID3.mp4 VID1.mp4 VID3.mp4 VID2.mp4
Algorithm: Iterate through all the .mp4 files (f1). Inside that loop, iterate through all the .mp4 files again (f2). If f1 != f2, then process the combination.
Assuming that your script to combine videos is called combine-videos.sh, here's a script to do what you are asking (I named it combo-script.sh):
#!/bin/sh for f1 in `ls *.mp4` do for f2 in `ls *.mp4` do if [ $f1 != $f2 ] then echo combine-videos.sh $f1 $f2 fi done done
Remove the echo when you are ready to actually run the script. Testing:
$ touch VID1.mp4 VID2.mp4 VID3.mp4 $ sh combo-script.sh combine-videos.sh VID1.mp4 VID2.mp4 combine-videos.sh VID1.mp4 VID3.mp4 combine-videos.sh VID2.mp4 VID1.mp4 combine-videos.sh VID2.mp4 VID3.mp4 combine-videos.sh VID3.mp4 VID1.mp4 combine-videos.sh VID3.mp4 VID2.mp4
Note that this script assumes that the .mp4 files are in the same directory as the script.