How to read and execute internal content line by line from a file… here is a solution to the problem.
How to read and execute internal content line by line from a file
How to read the contents of a file with spaces line by line and execute part of that line
For example, I have the following in my file
Hello world $(echo 9923,3443,434,344 | cut -d"," -f4)
Hello world $(echo 9923,3443,434,344 | cut -d"," -f2)
Hello world $(echo 9923,3443,434,344 | cut -d"," -f1)
My expected result is
Hello world 344
Hello world 3443
Hello world 9223
What I get is echo in the while loop
Hello world $(echo 9923,3443,434,344 | cut -d"," -f4)
Hello world $(echo 9923,3443,434,344 | cut -d"," -f2)
Hello world $(echo 9923,3443,434,344 | cut -d"," -f1)
My code would look like this
while read LINE
do
echo $LINE
done < FILE
I tried several things like using backticks, double quotes, eval none of them seem to work.
Solution
Try this :
while read line; do
eval "echo $line";
done < FILE