我正在使用以下命令合并file1和file2以获取file3:
awk 'NR==FNR {a[$2]=$1; next} {$(NF+1) = a[$NF]} 1' file2 file1 > file3
当我在使用期望的bash脚本中使用此命令时,我得到的是file3为空(该命令正在手动运行)。
#!/bin/bash
# Bash Menu Script Example
outputMME="$( expect <<END
spawn ssh [email protected]
expect "Password: " { send "password\r" }
expect "# " { send "bash\r" }
expect "$ " { send "cd /tmp/DPE_CORE/home/atndn/eniq/\r" }
expect "$ " { send "awk 'NR==FNR{a[$2]=$1; next} {\\\$(NF+1) = a[$NF]} 1' file2 file1 > file3\r" }
END
)"
echo "$outputMME"
文件1:
471808241 29164840 1 10001 156197396
471722917 21067410 1 31001 135961856
471941441 20774160 1 7001 180995072
471568655 29042630 1 15001 157502996
471524711 20716360 1 4001 180226817
471873918 29583520 1 2001 128567298
471568650 29042631 1 15002 157502910
文件2:
610146 156197396
531101 135961856
704011 180226817
502216 128567298
707012 180995072
615246 157502996
685221 157502910
文件3:
471808241 29164840 1 10001 156197396 610146
471722917 21067410 1 31001 135961856 531101
471941441 20774160 1 7001 180995072 707012
471568655 29042630 1 15001 157502996 615246
471524711 20716360 1 4001 180226817 704011
471873918 29583520 1 2001 128567298 502216
471568650 29042631 1 15002 157502910 685221
要实施Steeldriver的评论:
outputMME="$(
expect <<'END'
#....^ [1]
spawn ssh [email protected]
expect "Password: " { send "password\r" }
expect "# " { send "bash\r" }
expect "$ " { send "cd /tmp/DPE_CORE/home/atndn/eniq/\r" }
expect "$ " {
send {awk 'NR==FNR{a[$2]=$1; next} {$(NF+1) = a[$NF]} 1' file2 file1 > file3}
#....^ [2]
send "\r"
}
expect "$ " { send "exit\r" }
expect "# " { send "exit\r" }
expect eof
END
)"
'END'
),以便bash不会在文档中进行变量(和其他)替换。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句