1833792 Members
2530 Online
110063 Solutions
New Discussion

Re: Update file

 
Son dam bi
Advisor

Update file


I have a file that have unix login id and user name, the format as below

user1 Peter
user2 Mary
user3 Tom
user4 Susan
"
"

I would like to update the user name to the .name file in each user's directory , for example , add Peter to the file ~user1/.name , add Mary to the file ~user2/.name etc , so the result should be as below .

$more ~user1/.name
Peter

$more ~user2/.name
Mary

$more ~user3/.name
Tom

$more ~user4/.name
Susan

except vi each user file , can advise what can i do to update all user name by a batch ? thx
2 REPLIES 2
Dennis Handly
Acclaimed Contributor

Re: Update file

while read user name; do
echo "$name" >> $(eval echo ~$user)/.name
done < name-file
Raj D.
Honored Contributor

Re: Update file

Son dam bi,

You can try like this,

for i in `cat username.data` #contains all the user name.
do
echo "Creating .name file for user = $i "
cat user_vs_username.data | grep $i | awk '{print $2}' > ~$i/.name
done


HTH,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "