I have this working:% cat read.sh!/bin/shfile=list.txtwhile read linedo    echo $linecut -d' ' -f27 | sed -n '$p' > file2done < $file% cat list.txt sftp> #!/bin/shsftp> sftp> cd u/aaasftp> ls -lrt x_*.csv-rwxr-xr-x    0 1001     1001     12274972 May 13 21:07 x_20150501.csv-rw-r--r--    0 1001     1001            0 May 13 21:44 x_20150601.csv-rw-r--r--    0 1001     1001            0 May 13 21:44 x_20150701.csv-rw-r--r--    0 1001     1001            0 May 13 21:44 x_20150801.csv-rw-r--r--    0 1001     1001            0 May 13 21:44 x_20150901.csv-rw-r--r--    0 1001     1001            0 May 13 21:45 x_20151001.csv-rw-r--r--    0 1001     1001            0 May 13 21:45 x_20151101.csv-rw-r--r--    0 1001     1001            0 May 13 21:45 x_20151201.csv% cat file2 x_20151201.csvFirst question:Is there something more glamorous to read just the very last item on the very last line? Would you use cut and sed? This is a redirect of a sftp directoy listing.Second question:Whatever is in file2, I want to have it read from a sftp batch file to get that exact file.% cat fetch.sh #!/bin/shcd u/aaa!sh read.sh!< file2 getbyeAs you can imagine, sftp doesn't like get provided without any file, so how can I read in file2 to get that file from the sftp server? % sftp -b fetch.sh user@pulse    sftp> #!/bin/sh    sftp>     sftp> cd u/aaa            sftp> !sh read.sh    sftp> #!/bin/sh    sftp> !< file2     x_20151201.csv    sftp> get    You must specify at least one path after a get command.
Shell read script for sftp
shell;scripting;sftp;bsd;read
You can combine all the actions in one command:sftp user@host:/path/to/file/$(tail -1 file1.txt |tr -s ' ' |cut -d ' ' -f 9)This will fetch the file into the current working directory. If you need to fetch the file into another directory specify the destination directory as a next argument to the sftp command.