Reputation: 1615
I have a text file, say, input.txt
and I want to run a command and write the output to another text file, say, output.txt
. I need to read values from input.txt
, each value is in a line, then I need to insert them in the command then write the result in output.txt
file. I tried the following and it works fine with me:
for i in `cat input.txt`; do command -m $i -b 100; echo $i; >> output.txt; done
Now, I need to make some improvements over this but I have little experience in Linux so I need some help.
What I need to do is:
1) Before each command result, I want to insert the value of i
separated by comma. For example:
i1,result1
i2,result2
i3,result3
2) I need to change the second fixed value that I used in my command from a fixed value (100) to a value read from input.txt
. So, the new input file which contains two values, say, newinput.txt
is as the following:
i1,value1
i2,value2
i3,value3
Upvotes: 0
Views: 5198
Reputation: 25589
Try this, in bash:
IFS=','
while read i val; do
echo -n "$i,"
command $i $val
done < input.txt > output.txt
Upvotes: 1