1

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
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
panbar
  • 95
  • 9
  • Possible duplicate of [Looping over pairs of values in bash](http://stackoverflow.com/questions/28725333/looping-over-pairs-of-values-in-bash) – tripleee Mar 24 '16 at 14:54

1 Answers1

1

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
chepner
  • 497,756
  • 71
  • 530
  • 681