如何逐行读取文件中的内容并执行该行的一部分
例如,我的文件中有以下内容
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)
我的预期结果将是
Hello world 344
Hello world 3443
Hello world 9223
我得到的是通过while循环回显
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)
我的代码将类似于
while read LINE
do
echo $LINE
done < FILE
我尝试了几个东西,比如使用反引号,双引号,eval似乎没什么用。
答案 0 :(得分:4)
试试这个:
while read line; do
eval "echo $line";
done < FILE