0

I have a bash script to retrieve files from ftp.

Now the files have one part a date string in the filename, but also undefined numbers that changes on every file. I want to download the files based on the date.

This is my code. I only need to do the wildcard trick, the ftp script is allready work.

filename=$(echo $TIMESTAMP'0***vel.radar.h5') 

The stars are 3 digits with different numbers that i can't estimate, so i would use the wildcard for them.

Thank you

2
  • What is the question? Also note that * stands for any number of characters, so *** is the same as *. The wildcard for one character is ?. Commented Apr 13, 2014 at 19:30
  • I need to download a file from an ftp server with get $filename Commented Apr 13, 2014 at 19:35

2 Answers 2

1

It sounds like you want to handle multiple files, but your script can only handle one file at a time. Furthermore, because you specified FTP, it sounds like the files are on the FTP server, in which case local filename expansion will not help.

You probably want to use the ftp client's mget command to download multiple files matching a pattern on the remote side. You also want to include $TIMESTAMP as part of the pattern. I'd suggest something like this:

ftp remote-hostname <<EOF cd path/to/log/files prompt mget ${TIMESTAMP}0???vel.radar.h5 bye EOF 

This uses a here-document (<<EOF to EOF on a line by itself) to supply input text to the ftp commmand. It will expand the variable $TIMESTAMP so it becomes part of the mget command, e.g. if $TIMESTAMP was 12345, the ftp command will be told mget 123450???vel.radar.h5.

Sign up to request clarification or add additional context in comments.

Comments

0

With the ? characters you include not only numbers, but any character. So if you want to include only numbers, you can replace the ??? characters with [0-9][0-9][0-9].

Example:

If you have the following files:

$ ls 0123vel.h5 0333vel.h5 033vel.h5 0pecvel.h5

with this ls you show the correct files:

$ ls 0[0-9][0-9][0-9]vel.radar.h5 0123vel.h5 0333vel.h5

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.