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

    users  uid
    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.

link|improve this question

72% accept rate
feedback

1 Answer

up vote 4 down vote accepted
sed 1d users_uid | awk '{print "usermod -u "$2" "$1}' | bash
link|improve this answer
Thanks It worked ! But the sed is not required i think. # cat users_uid |awk '{print "usermod -u "$2" "$1}' | bash – nitins Dec 8 '11 at 13:03
1  
Sed it required in case the first line is like in your example users uid. Otherwise it isn't required. – Rush Dec 8 '11 at 13:06
@nitins: if the users_uid file doesn't contain column name (the first line), no need to use cat: awk '{ print "usermod -u "$2" "$1 }' users_uid | bash. – quanta Dec 8 '11 at 13:14
Yes you are correct. I actually don't have that line. Just added here to make it clear – nitins Dec 8 '11 at 13:15
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.