且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

awk:致命:无法打开文件“"进行读取(没有这样的文件或目录)

更新时间:2022-05-18 22:52:51

我相信 $ jalisco 变量将x-y坐标保存为字符串中的空格.显然 $ jalisco 不是文件,因此您的最后2个awk命令给出了错误.

I believe the $jalisco variable is holding x-y co-ordinates separated by space in a string. Obviously $jalisco is not a file hence your last 2 awk commands are giving errors.

您可以使用此:

x=$(awk '{print $1}' <<< "${jalisco}")
y=$(awk '{print $2}' <<< "${jalisco}")

或者更好的方法是,使用流程替换:从您的第一个awk本身获取两个值:

Or better yet, get both values from your first awk itself using process substitution:

read x y < <(awk 'NR==1055' "$nodes_file")

还请注意,您的 awk 命令可以简化为:

Also note that your awk command can be shortened to just:

awk 'NR==1055' "$nodes_file"

默认操作是打印该行,因此当条件 NR == 1055 为true时,awk将执行此操作.

The default action is to print the line, so this is what awk will do when the condition NR==1055 is true.