如何使用"md5sum"处理"awk"的"$1"



test文件示例:

cat <<'EOF'> test
/boot/efi/EFI/debian/grubx64.efi root root 700 1625230722
/boot/efi/EFI/debian/mmx64.efi root root 700 1625230722
/boot/efi/EFI/debian/shimx64.efi root root 700 1625230722
/boot/grub/fonts/unicode.pf2 root root 644 1625230723
EOF

我计划在test文件中再添加一列,新添加的列的值取决于第一列(md5sum --binary($1)(,例如md5sum --binary /boot/efi/EFI/debian/grubx64.efi

我的脚本是awk '{ cmd = "md5sum --binary" close(cmd) $(NF+1) = (cmd($1)); print }' test > test_new,但出现以下错误:

awk: line 1: syntax error at or near =

我是awk的新手,有什么问题吗?

这个awk应该工作:

awk '{cmd = "md5sum --binary 47" $1 "47"; 
if ((cmd | getline out) > 0) print $0, out; close(cmd)}' file.test

然而,对于这样的任务,bash循环应该做得更好,因为我们只使用第一列调用外部程序:

while read -r col1 rest; do
echo "$col1 $rest" "$(md5sum --binary "$col1")"
done < file.test

最新更新