Linux – Shell script to change uid for user

bashlinuxshellshell-scripting

I have a file (users_uid) with users and uid are two parameters as given below :

    assds  611
    dsdsd  612
    xyzx   613
    rerer  614

These users exist in the machine. I want to change the uid of each user to that value given right for the username. I know that I can modify the uid using usermod -u <uid> <user>. But I don't know how to read the two values in the file and put them as the 2 parameters in a for loop with usermod command.

Best Answer

awk '{print "usermod -u "$2" "$1}' users_uid | bash