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?
            Asked
            
        
        
            Active
            
        
            Viewed 55 times
        
    0
            
            
        - 
                    So you have a file that has a list of temperatures, and you want to get the converted temperature for each one, so you can do something with each one? If so, you can look [here](http://stackoverflow.com/questions/7619438/bash-read-a-file-line-by-line-and-process-each-segment-as-parameters-to-other-p) for part of it – Eric Renouf Dec 07 '16 at 16:45
- 
                    How does the C program read the data? – cdarke Dec 07 '16 at 19:39
- 
                    What is wrong with reading one line a time in the C program? I do not understand why you would want something like `while read -r line; do cprog "${line}"; done`. – Walter A Dec 07 '16 at 21:59
1 Answers
1
            
            
        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)
 
    
    
        pjh
        
- 6,388
- 2
- 16
- 17
