Grep text in awk after pattern
I am trying to execute following command but I am not able to do it.
Code:
awk -F: '{ system("passwd -S " $1)}' /etc/passwd | grep LK Please help me to achieve this using same awk command. I have tried Code:
awk -F: '{ system("passwd -S " $1)/LK/}' /etc/passwd |
Can I ask why are you using the separation character ':'?
On my system, the columns generated by passwd -S appear to be space-separated. (I have other questions as well, but thought we'd start with that one ;)) |
Hi there,
Try this: Code:
awk -F: '{ "passwd -S " $1 | getline status; split(status,sf," "); if (sf[2] == "LK") print sf[1];}' /etc/passwd With recent versions of "passwd" you can show the status of all accounts in one go, making this possible: Code:
passwd -S -a | awk '/ LK / {print $1} |
Quote:
|
Quote:
So, why doesn't Code:
passwd -S -a | awk -F" " '$2 ~ /L/' Edit: I've used L instead of LK because man passwd on my system indicates that only this letter indicates a locked password. |
Hi hydrurga,
I think it depends on your version of "passwd". On my openSUSE Tumbelweed laptop your command works ("-a" option is present, and output shows "L" only). On al older Centos 6 server I found that "-a" doesn't exist, and output shows "LK" as per unclesamcrazy's original post. |
Quote:
|
All times are GMT -5. The time now is 05:35 PM. |