Passing lines from the text file of a list of files to or as arguments
Using a while read
loop:
while read -r file1 file2 trash; do
something with "$file1" and "$file2"
done < /path/to/input_file
This will read your input file line by line, setting file1
and file2
with the first and second columns respectively. trash
is probably unnecessary but I like to include it to handle things you may encounter such as:
file1.fastq.gz file2.fastq.gz foo
If your file contained a line like the above and you did not include the trash
variable (or one similar), your file2
variable would be set to: file2.fastq.gz foo
xargs
is another way, if your file format is exactly as you say: two whitespace-separated fields per line (noting the ...
ellipsis).
< input xargs -n2 ./script-here
... will read the file named input
line-by-line and pass two arguments to ./script-here
.
You can rearrange the redirection:
xargs -n2 ./script-here < input
... if it makes better intuitive sense to you.