1

I have a txt files with all the file names I need to analyze. I have this file (inputFile.txt) :

/path/file1a  path/file1b 
/path/file2a  path/file2b

i have a code which needs two two input files in order to run.

./Analyzethis /path/file1a /path/file1b

i am trying to create a bash loop to go through my txt files, read through each row and run my code.

I had

#!/bin/bash
IFS=$'\n'; for FILE1 in `cat inputFile.txt`; do ./Analyzethis $FILE1; done

but, it doesnt work. How can i loop through each row and use the columns with the bash loop?

IP25
  • 11
  • A very simple google search for "read file in bash" gives you the answer. eg: https://www.cyberciti.biz/faq/unix-howto-read-line-by-line-from-file/ – Philip Couling Mar 20 '19 at 14:43

1 Answers1

5

This is a bash FAQ: How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?

while read -r first second; do 
    ./Analyzethis "$first" "$second"
done < inputFile.txt

make sure you quote your variables

While you're reading that FAQ page, make sure you read Don't try to use "for"

glenn jackman
  • 85,964