Artificial intelligent assistant

Awk field printing within the ternary operator If you're familiar with DISA STIGs, the test for RHEL-06-000518 is /bin/rpm -Va 2>/dev/null \ | /bin/grep '^.M' What I want to do is pull just the file name out of that test, and make pretty output with the package name and the offending file. However, my awk isn't doing it. Here's what I'm trying: /bin/rpm -Va 2>/dev/null \ | grep '^.M' \ | awk '{print ($2 ~ /./ ? $3 : $2)}' which, in theory, tells awk to print field 3 if field 2 is one of the single-character file types (%config, %documentation, etc., see the rpm man page) However, what I get is the file name if-and-only-if ($2 ~ /./). Otherwise, I just get a blank line, even if I substitute $0 for that final $2. What am I missing?

Your test `$2 ~ /./` is always true, except when `$2` is the empty string, ie when there is 0 or 1 field in the line. You should try `$2 ~ /^.$/`.

You can also combine the grep and awk into one:


awk '/^.M/ {print ($2 ~ /^.$/ ? $3 : $2)}'

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 26bd651b1476832aef25efa3c5703e95