0

I am trying to download a chunk of files from an application. The shell command for it is 'go filename download'.

I have a text file containing all the filenames I have to download. All I want to do is to run a script/command such that when the above command is executed 1. the filenames are picked up from the textfile & executed using the above command 2. existing files/unavailable files are skipped 3. the process then continues with the next files in the list

So far I have this idea of using an operator like go $ download & then feed the operator with the text file containing the filenames list. Thanks in advance.

1 Answer 1

2

For Windows, you can use for /f to process the file and create a command from it. The following script supergo.cmd shows how this can be done:

@setlocal enableextensions enabledelayedexpansion
@echo off
for /f "delims=" %%f in (list.txt) do (
    echo go "%%f" download
)
endlocal

The following transcripts shows it in operation:

C:\Pax> type list.txt
file1.txt
file number 2.txt
another file.jpg

C:\Pax> supergo
go "file1.txt" download
go "file number 2.txt" download
go "another file.jpg" download

If you're using a shell like bash, you can use sed to create a temporary script from the input file then run that:

#!/bin/bash
sed -e "s/^/echo go '/" -e "s/$/' download/" list.txt >/tmp/tempexec.$$
chmod u+x /tmp/tempexec.$$
. /tmp/tempexec.$$
rm -rf /tmp/tempexec.$$

This puts an echo go ' at the start of each line, a ' download at the end, then marks it executable and executes it.

In both cases (Windows and bash), remove the echo to get it to do the real work.

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

2 Comments

how about in case a file is missing or has already been downloaded. How can I skip/handle such errors because last time I did something similar to what you said it terminated when it faced some problem.
@deppfx, I'd start with that script and get it working then ask for improvements. Since you don't know whether the remote file is different from the local one, you'll have to download it just in case. Unless you can supply a way of checking, of course (checksums, sizes, etc).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.