This list is great! I got many replies in just a short time. Thanks to
all that responded to me.
Here are 2 examples. Original question follows at the end of message.
thanks,
Allan
_____________________________________________________________________
ext=`awk 'BEGIN{FS="/"};{printf "\\,%s",$NF}' <filename>`
sed `/users:/s/$/'$ext'/` /etc/group > group.new
------------------------------------------------------------------------
-----------------------------------------------
>#!/bin/ksh
>
>USER_FILE=$HOME/users # Your file of user's home directories
>GROUP_FILE=$HOME/group # Could be /etc/group
>GROUP=users
>
># Read the users, constructing ",user1,user2..." list
>
>LIST=
>while read LINE; do
> LIST="$LIST,${LINE##*/}" # Add basename to list
>done < $USER_FILE
>
>rm -f $GROUP_FILE.new # Get rid of it, if it exists
>
># Read group file, writng it to new group file
># When we hit correct list (1st field matches),
># append list and write out new line
>
>while read LINE; do
> if [[ ${LINE%%:*} = $GROUP ]] # Right line in file?
> then print "$LINE$LIST" >> $GROUP_FILE.new # Yes, append list
> else print "$LINE" >> $GROUP_FILE.new # No
> fi
>done < $GROUP_FILE
>
>mv $GROUP_FILE $GROUP_FILE.old # Save current group file
>mv $GROUP_FILE.new $GROUP_FILE # Make new file the group file
>
># Note that there'll be a comma in front of the list of users.
># This is OK if there are other users in that group.
># If these are the first users in that group, you'll have to
># vi /etc/group (or use your editor of choice)
># and delete the comma from the ":," in the rewritten line
------------------------------------------------------------------------
----------------------------------------
Original question....
I need some help in korn shell scripting again. I am trying to write a
ksh script that would take
a file which looks like the following...
/home/user1
/home/user2
/home/user3
.
.
.
/home/user400
and make the output look like so...
user1,user2,user3,...user400
and then append it to the users group in the /etc/group file.
I know just a cut and paste after getting the right output would do, but
for learning
sake, I'd like to see the code that appends the output to the group file
in the correct place.
Received on Sat Oct 25 1997 - 00:20:55 NZDT