Reply addresses set by hand to work around broken defaults. (Again.)
suser wrote:
I am trying to create a script to go through /etc/passwd and change anyone who's home directory is "/mnt/home" to "/mnt/<username on linux server>". I have been playing around with loops and regular expressions but have not got anything close to the results i want. I have roughly 1000 users so changing them all by hand is quite the pain. so basically im trying to do something like the following: Original - user:x:1000:100:user:/mnt/home:/bin/bash what i want - user:x:1000:100:user:/mnt/user:/bin/bash any suggestions? thanks in advance!
This is not really a bash-related question as far as I can tell. I would probably do that with sed, e.g. sed /etc/passwd -e "s/100:\([^:]*\):\/mnt\/home:/\1:\/mnt\/\1:/g" or equivalently (I think) but more tersely sed /etc/passwd -e "s/100:\([^:]*\)\(:\/mnt\/\)home/\1\2\1/g" You could, of course, add the '-i' flag to have sed make the changes to the file in place - but I would recommend, instead, redirecting the output into a separate file and confirming that it is correct, then copying the new file into place. -- The Wanderer sticks his neck out again Warning: Simply because I argue an issue does not mean I agree with any side of it. Secrecy is the beginning of tyranny.