我有一个文件(test.txt),其内容类似于
/the/path/foo.txt foo.txt
/the/paths/doo.txt doo.txt
/the/path/foo.pl foo.pl
/the/paths/doo.pl doo.pl
/the/path1/soo.csv soo.csv
/the/path2/moo.csv moo.csv
我希望将awk {print $ 1}保存到variable1并将awk {print $ 2}保存到bash脚本中的variable2,即variable1获取/the/path/foo.txt,variable2获取foo.txt等等
由于
答案 0 :(得分:6)
您可以使用read
内置来捕获变量并为变量分配字段(假设您的路径中没有空格):
while read -r var1 var2; do
# do something with variables
done < text.txt