I have a question regarding sending data from a file line by line to a C program that will then convert the data's values from Fahrenheit to Kelvin. How do I read in the program line by line and then grab the output line by line back into my script?
1 Answer
It's not really clear what is required here because the interface to the converter program is not specified. Assuming that the program is called f2k, that it reads Fahrenheit values one-per-line from standard input and writes the converted values one-per-line to standard output, and that the file fahrenheits.txt contains a list of Fahrenheit values, one-per-line, this will put a newline-separated list of the Kelvin values into the kelvins variable:
kelvins=$(f2k <fahrenheits.txt)
while read -r line; do cprog "${line}"; done.