Yuvi
Yuvi

Reputation: 149

How to read line by line from a file and execute inner contents

How do I read contents from a file line by line with spaces and execute a portion 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 would be

Hello world 344
Hello world 3443
Hello world 9223

What I get is by echoing 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 will be something like

while read LINE
do
     echo $LINE
done < FILE

I have tried several things like using backticks,double quotes,eval nothing seems to work.

Upvotes: 3

Views: 741

Answers (1)

Oleksii Shmalko
Oleksii Shmalko

Reputation: 3768

Try this:

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

Upvotes: 5

Related Questions