Answer the question
In order to leave comments, you need to log in
How to parse an array?
Hello. Task: compare 2 arrays of files sorted into folders, if there is a 100% match, then move all files from folder A to folder B, where this match was found.
array one, contains folders A find ./Downloads -type f -iname "*.mkv"
array two, contains folders B find ./Serials -type f -iname "*.mkv"
like this now I take and sort movie files, but everything is simple here
#!/bin/bash
#зрим в корень
cd /
#перемещаем фильмы
find /volume1/Geroev_Avenue_18/Downloads -maxdepth 1 -type f -iname "*.mkv" -exec sh -c 'x="{}"; mv "$x" /volume1/Geroev_Avenue_18/Shared_Videos/Films' \;
Answer the question
In order to leave comments, you need to log in
Well, look here, several options
have already been sorted out compared to arrays.
How to compare two arrays in bash?
Here, of course, input data is needed, but again, if this is a very large number of files, then there may be the same arguments, etc., in general, it’s still not a very quick solution.
BUT the logic is this.
1. let's create two arrays.
2. save only the file name from the first array into a separate variable.
3. we create a loop and sort through this file, in an array of two, if there is a match, then copy it to the full path to this file.
Option 2 is more crutch, but it also
happens that you do not use the second array, but simply run 2 find each time with an exact match. find ./Serials -type f -iname "1110101.mkv"
millet
is something like this, but in this version you will run a find every time, but it is with a given specific file and the depth is small, and as I understand it, you don’t really need performance.
But in this version, you will understand what needs to be done without involving the creation of methods and two arrays.
And most importantly, there are no restrictions on the size of these arrays.
#!/bin/sh
MASSIV_1=$(find /volume1/Geroev_Avenue_18/Downloads -maxdepth 1 -type f -iname "*.mkv")
for ELEMENT in $MASSIV_1_FILMAME
do
find ./Serials -type f -iname "$MASSIV_1_FILMAME -exec cp {} $MASSIV_1_DIR \;"
fi
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question