A program has the output set to 2 decimal place floats, one on each line in the file. Depending on the execution, many files can be output, each with the filename cancer.ex#, where # is the number of times the program was executed from a script.
The professor has provided an awk script as the first step to generating a 95% confidence chart using gnuplot. I’d like to convert the output to to the format
conf $1 $2 $3 var#
where # is the number from cancer.ex#
I’ve developed the following:
#!/bin/bash
Files=Output/*
String
for f in $Files
do
String="conf "
cat $f | while read LINE
do
String="$LINE "
done
echo $String
done
I know a number of steps are missing, as I’ve just started putting this together. My problem is executing the concatenation part, as it simply doesn’t work. There is no output, nada when executing the script above. However, if I change String="$LINE to echo $LINE, then I get all the output of the files put on the terminal.
Is there a workable appending function for variables inside a loop in bash?
The subtle difference with
< "$f"instead of pipingcat $fis mainly, that the while loop would execute in a subshell due the pipe, and the variable in the for loop would not actually be updated because of the subshell.Note also, how, at various points I made the filename handling more robust (accepting filenames with spaces, e.g.)
Out of the box?
That all said, I suspect you might be done with simply
Proof of concept with dummy data:
Output