kvway kvway - 7 months ago 15
Bash Question

Running last in awk [Solaris]

How can i run

last
command for every matched line in awk?

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


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

Answer

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

or:

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