0

I would like to download files from a list. e.g. list.txt is the list file. It contains the list of file names:

pic_01.jpg
pic_02.jpg
pic_xxx.jpg

I need a loop which takes out the file name one by one and write it into an another file (just one name). The download script will use this single file name.

To summarize: send a file name from a list to another file, which contains only one file name (probably with a loop).

1

You can read the file line by line with a while loop and echo each one to a new file:

#!/bin/bash
while IFS='' read -r l || [[ -n "$l" ]]; do
    echo $l >$(mktemp -p.)
done <list.txt

This will loop over every line of list.txt and print the whole line to a tempfile created in the current directory. By default mktemp uses the template tmp.XXXXXXXXXX to create the files – the Xs are replaced by random characters – you can adapt that to your needs by specifying a different template, e.g. making it mktemp -p. file.XXXXX.

Further reading:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.