I have a file called lastlogin_1 that contains a list of usernames. I would like to put together a quick loop script that will use a variable (the contents of lastlogin_1 file) and grep all directories and sub directories in the current directory (/in/the/current/directory) for each username in the lastlogin_1 file and remove all entries of the usernames that exist in files under these directories.
The files contain information as follows: (user access to various menus)
The lastlogin_1 file contains entries as follows:
jamesm> more lastlogin_1
aaron
adamb
alan
alanr
alanr
alecia
aleda
alexs
alfred
Should the username be removed it will leave a double comma ,, in the file which might cause problems with other users access so I would like to remove only the comma following the user being removed.
Can someone point me in the right direction of how to do this with the use of a script. I have tried a few things but failing at the first hurdle when trying to set the variable ie
USERS=${<Lastlogin_1} or USERS= awk '{print $1}' lastlogin_1
#!/bin/bash
USERS=$(awk -F: '{print $3}' lastlogin_1 | tr ',' '\n')
for U in $USERS
do
echo "$U" # Just for testing purpose
# and further processing
done
Thanks for the responses. Using the following (changed to $1)
USERS=$(awk -F: '{print $1}' lastlogin_1 | tr ',' '\n')
for U in $USERS
do
echo "$U" # Just for testing purpose
# and further processing
done
outputs what is already in the lastlogin_1 file, as does
USERS=$(awk -F: '{print $1}' lastlogin_1)
for U in $USERS
do
echo "$U" # Just for testing purpose
# and further processing
done
I have many files in various directories and sub-directories that contain all the users in the variable $USERS. I would like to remove each user from every file they exist in under the main
directory= /apps/fourgen/accounting/menu.
The files that contain the users I want to remove have the following format
Now that I have the variable $USERS how do I search every file from the main directory including all sub-directories and remove all existing entries for each username within the variable.