Reputation: 95
I want to perform a iterative task on a bunch of similar files with similar partial files names contain "{$ID}". The program is running for each of the separate files manually. I wanted to write a for loop in shell to take 'ID' from a txt file and do the task. I am unable to give the input argument ID in the for loop from the values in coloumn1 of test.txt file Eaxmple:
for ID in 'values in coloumn1 of test.txt file'
do
file1=xyz_{$ID}.txt
file2=abc_{$ID}.txt
execute the defined function using file1 and file2
write to > out_{$ID}.txt
done
Upvotes: 1
Views: 365
Reputation: 531808
Iterate over the file with a while
loop, letting read
both input a line from the file and splitting the first column off each line.
while read -r ID rest; do
...
done < test.txt
If the columns are delimited by a character other than whitespace, use IFS
to specify that single character.
# comma-delimited files
while IFS=, read -r ID rest; do
...
done < test.txt
Upvotes: 1