Home > Net >  Removing array entries from lastlog command bash
Removing array entries from lastlog command bash

Time:01-21

I am running a command in a script which saves usernames in an array and I was wondering if there is a simple solution to removing these usernames during a run of the lastlog command.

I was thinking of something like this:

lastlog | grep -v "Never logged in" | grep -v ${excluded_users} | awk '{print $1,":",$5,$6,$9 }'

If it at all works please let me know.

Otherwise I'm open for different suggestions and or solutions.

Thank you in advance.

CodePudding user response:

To extend your idea, you could put the list of users into a file and do a ... | grep -vwFf excluded_users.txt | .....

Perhaps a more robust way to remove the users would be to do it in your awk command:

awk '$1 ~! /userA|userB|userC/ {print ... }' 
  •  Tags:  
  • Related