test
file as example:
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
I plan to add one more column to test
file,the value of new added column depends on the first column(md5sum --binary($1)
),such as md5sum --binary /boot/efi/EFI/debian/grubx64.efi
.
My script is awk '{ cmd = "md5sum --binary" close(cmd) $(NF+1) = (cmd($1)); print }' test > test_new
but got error as below:
awk: line 1: syntax error at or near =
I am new to awk
,what's the problem?
This awk
should work:
awk '{cmd = "md5sum --binary \047" $1 "\047";
if ((cmd | getline out) > 0) print $0, out; close(cmd)}' file.test
However for task like this a bash
loop should do job better as we are calling an external program using just the first column:
while read -r col1 rest; do
echo "$col1 $rest" "$(md5sum --binary "$col1")"
done < file.test