I want to run the basename command on a certain awk field.
echo "1 /this/is/a/path" | awk '{print $1" "system("/usr/bin/basename " $2)}'
but the output always produces a 0 from the system command. How do I print the real output?
I want to run the basename command on a certain awk field.
echo "1 /this/is/a/path" | awk '{print $1" "system("/usr/bin/basename " $2)}'
but the output always produces a 0 from the system command. How do I print the real output?
POSIXly:
$ echo "1 /this/is/a/path" | awk '
{
cmd = "/usr/bin/basename -- " $2;
cmd | getline out;
print $1, out;
close(cmd);
}'
1 path