'Using makefile to download a file from AWS to local

I want to set up a target which downloads the latest s3 file containing _id_config within a path. So I know I can get the name of file I am interested in by

FILE=$(shell aws s3 ls s3:blah//xyz/mno/here  --recursive | sort | tail -n 2 | awk '{print $4}' | grep id_config)

Now, I want to download the file to local with something like

download_stuff:
    aws s3 cp s3://prod_an.live.data/$FILE .

But when I run this, my $FILE has some extra stuff like

aws s3 cp s3://blah/2022-02-17 16:02:21    2098880 blah//xyz/mno/here54fa8c68e41_id_config.json . 

Unknown options: 2098880,blah/xyz/mno/here54fa8c68e41_id_config.json,.

Please can someone help me understand why 2098880 and the spaces are there in the output and how to resolve this. Thank you in advance.



Solution 1:[1]

Suggesting a trick with ls options -1 and -t to get the latest files in a folder:

FILE=$(shell aws s3 ls -1t s3:blah//xyz/mno/here  |head -n 2 | grep id_config)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dudi Boy