0

I have a bash script that I am converting .jpg files, zipping them, then (because of the destination limitations), breaking the zip file into smaller chunks. I end with a series of files like this:

eab_ph01.zip
eab_ph02.zip
eab_ph03.zip
eab_ph04.zip
eab_ph05.zip
eab_ph06.zip
eab_ph07.zip
eab_pho1.zip
eab_photos.zip

Or, it is possible the files will look like this:

eab_pho1.zip
eab_pho2.zip
eab_pho3.zip
eab_pho4.zip
eab_pho5.zip
eab_pho6.zip
eab_pho7.zip

I am able to select the specific files, whether it uses the prefix pho or ph with the following regular expression

ls | grep -P "eab_pho?[0-9]?[0-9]?.zip"

Then I need to start an SFTP session. I need to PUT only the segmented files and not get the original file eab_photos.zip.

How can I include the regular expressions to put the specific files that I want?

Alireza
  • 2,103
  • 1
  • 6
  • 19
Aaron
  • 51
  • 6
  • There might be a way of accomplishing this using GLOB(7) used by sftp. Another option could be to generate a batch file with your shell and then feeding it to sftp with -b. – UncleCarl Aug 11 '21 at 22:58
  • 1
    `find . -type f -name 'eab_pho[0-9]?.zip' -print0 | xargs -r0 -I {} sftp {} user@host:` similar to https://stackoverflow.com/a/39054583/2834978 – LMC Aug 11 '21 at 23:06
  • You cannot get original file named 'eab_photos.zip' with your regex pattern `eab_pho?[0-9]?[0-9]?.zip` https://regex101.com/r/jLRSUq/1 Can you provide result you want to get? – doctorgu Aug 11 '21 at 23:57
  • Why not just `eab_ph*.zip` ? – Nic3500 Aug 12 '21 at 00:51
  • eab_ph*.zip will also pick up the original zip file that has many gigs of images. We cannot send the original zipped file. We must only send the parts. However, what we may decide to do is to rename the original file eab_photos.zip to eab_photos.orig.zip so that a simple eab_ph??.zip will work. It is not as elegant, but it will work. @LMC, I did try your method but in my time limitations was not able to get that string to work. – Aaron Aug 12 '21 at 13:52

0 Answers0