Processing a List of Files from an Input File
Gregg
Suppose we have a list of files stored in a text file and we want to perform an operation on each of them within a bash script. How would we go about doing that? Well, there are several options, here are a few.
$ cat input-files.txtfile-1.txtfile-2.txtfile-3.txtfile-4.txtfile-5.txtfile-6.txtfile-7.txtfile-8.txtfile-9.txt
Now, if we want to operate on each file in this list we can do something like this:
while IFS= read -r filenamedoecho "Do something on ${filename} here..."done < "input-files.txt"
or alternatively,
input="input-files.txt"while IFS= read -r filenamedoprintf '%s\n' "${filename}"done < "${input}"