I am trying to select elements in a list of files using a sequence. For this I have created a list of all my files following a pattern in a folder:
ls -d -1 /my/path/S1*.zip
Where the output is:
/my/path/S1A_IW_SLC__1SDV_20180412T171648_20180412T171715_021437_024E95_BDA1.zip /my/path/S1A_IW_SLC__1SDV_20180424T171648_20180424T171715_021612_02540A_BB21.zip /my/path/S1A_IW_SLC__1SDV_20180506T171649_20180506T171716_021787_025996_98AB.zip /my/path/S1A_IW_SLC__1SDV_20180518T171649_20180518T171716_021962_025F27_A15C.zip /my/path/S1A_IW_SLC__1SDV_20180530T171650_20180530T171717_022137_0264C8_5D94.zip /my/path/S1A_IW_SLC__1SDV_20180611T171651_20180611T171718_022312_026A3D_BBFC.zip /my/path/S1A_IW_SLC__1SDV_20180623T171652_20180623T171719_022487_026F7C_450E.zip /my/path/S1A_IW_SLC__1SDV_20180623T171652_20180623T171719_543456_64324F_452W.zip
I would like to create a
forloop in which for every iteration, the files are processed in groups of two. So, in the first iteration, file in position 1 in my list and file in position 2 are processed. In the second interation, file in position 3 and file in position 4, etc.
To make it simpler, I will take the example of unzipping these files in grousp of 2:
for i in $(ls -d -1 /shared/Training/WROC0320_UrbanMapping_Germany/Original/S1*.zip) do unzip i unizp i+1 # Not sure if i+1 works like that in `bash` done
The problem I see with this approach is that in the first iteration it will work (
i will be 1 and 2) but in the secodn
i will be 2 and 3 and it should be 3 and 4.
My question is then, how to iterate over the result of
ls is such way?