2

I have a long list of data files that I need to copy over to my server, they have the names

data_1.dat
data_2.dat
data_3.dat
...
data_100.dat

Starting from data_1.dat, I would like to get all the files where the number is increased by 3, i.e. data_4.dat, data_7.dat, data_10.dat, ...

Is there a way to specify this? Right now I am doing in manually using get data_4.dat, but there must be a way to automatize this.

  • 2
    create a list with using seq 1 3 100 – Ipor Sircer Sep 8 '16 at 14:43
3

On Linux:

printf -- '-get data_%d.txt\n' $(seq 1 3 100) | sftp -b - user@example.com

On BSD (with no seq(1) in sight):

printf -- '-get data_%d.txt\n' $(jot 100 1 100 3) | sftp -b - user@example.com
1

bash supports C style looping construct, you can leverage that:

for ((i=1; i<=100; i+=3)); do echo file_$i.dat; done

Replace echo file_$i.dat with the operation you want on the file.


Example:

$ for ((i=1; i<=100; i+=3)); do echo file_$i.dat; done
file_1.dat
file_4.dat
file_7.dat
file_10.dat
file_13.dat
file_16.dat
file_19.dat
file_22.dat
file_25.dat
file_28.dat
file_31.dat
file_34.dat
file_37.dat
file_40.dat
file_43.dat
file_46.dat
file_49.dat
file_52.dat
file_55.dat
file_58.dat
file_61.dat
file_64.dat
file_67.dat
file_70.dat
file_73.dat
file_76.dat
file_79.dat
file_82.dat
file_85.dat
file_88.dat
file_91.dat
file_94.dat
file_97.dat
file_100.dat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.