Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching and chaginging

Status
Not open for further replies.

paublo

ISP
Sep 14, 2006
127
US
1st, thanks in advance.

heres the problem.

I have a passwd file that i want to change 2 things in it. The home directory location and the word dummy to the actual user's name.

heres an example of whats in the passwd file:

username:x:510:50000:customername:/home/DIR/dummy:/bin/nologin

basically i want to take the 1st letter only of the username, in this case the user is "username", so i want to take the letter u and replace "DIR" with u and to also replace the word "dummy" with the actual username. in this case "username"

im sure theres a way in sed or awk to do this, unfortuantly im not that good with either of them.

thanks again.

 
WOW that worked. thats impressive :). thanks.

I will be trying to break that down for the next 30 min.

not sure if i can ask you one more thing, if i had a file with just usernames in it and want to created them in /home/1stletter/username, where 1stletter is the 1st letter of the username.

so i have a file with:

auser
buser
cuser

and i want to create

/home/a/auser
/home/b/buser etc

i know

LIST=`$filename`;

for FILE in $LIST

do

sed comand here to take out the 1st letter of the useranme and assign it to another variable.

then i could do

mkdir -p /home/$VAR/$FILE

i know the rest

done

thanks again very much

 
Hi

Code:
[blue]master #[/blue] cat namelist
auser
buser
cuser

[blue]master #[/blue] sed 's,\(.\),/home/\1/\1,' namelist
/home/a/auser
/home/b/buser
/home/c/cuser

[blue]master #[/blue] sed 's,\(.\),make -p /home/\1/\1,' namelist
make -p /home/a/auser
make -p /home/b/buser
make -p /home/c/cuser

[blue]master #[/blue] sed 's,\(.\),make -p /home/\1/\1,' namelist | sh
[gray]# here says nothing, just creates the directories[/gray]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top