How to read line by line from file and execute inner content

How to read content from line by line with spaces 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 output would be

Hello world 344
Hello world 3443
Hello world 9223

      

What I get is an echo in a 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 be something like

while read LINE
do
     echo $LINE
done < FILE

      

I've tried a few things like using backreferences, double quotes, eval nothing works.

+3


source to share


1 answer


Try the following:



while read line; do
    eval "echo $line";
done < FILE

      

+4


source







All Articles