kvway kvway - 11 months ago 49
Bash Question

Running last in awk [Solaris]

How can i run

command for every matched line in awk?

ypcat passwd | awk -F":" '/:John / { system("last" $1) }'

I'm trying to execute the
command for every user that is named John but It does not print anything.


Your approach is wrong, awk is not shell. awk is designed to manipulate text not to call other tools from, that is what a shell is for This may be what you want, depending on what last is/does:

ypcat passwd | awk -F":" '/:John /{print $1}' | xargs last


ypcat passwd | awk -F":" '/:John /{print $1}' | xargs -n 1 last