How to update an entry of another file in a Shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to update an entry of another file in a Shell script?
# 1  
Old 07-21-2012
Question How to update an entry of another file in a Shell script?

Hi all,

Say I have a shell script called update_password.sh - in this script I want to perform a task to update a specified entry of another file (e.g. users.passpords)

update_password.sh
Code:
#!/bin/bash -e

PW_FILE_DIR="${A_DIR}/.../..."
PW_FILE="users.passwords"

I want to update the password of the user whose name is Michael!

users.passwords
Code:
James: ?????
David: ?????
Michael: ?????                       //only this entry to be updated
Frank: ?????
Thomas: ?????

May I know how to achieve or could anyone please pass me a tutorial....Thanks!
# 2  
Old 07-21-2012
Like this?
Code:
name="Michael"
pass="newpassword"
sed '/^\('"$name"': \).*/s//\1'"$pass"'/' users.passwords > temp
mv temp users.passwords

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 07-22-2012
Quote:
Originally Posted by elixir_sinari
Like this?
Code:
name="Michael"
pass="newpassword"
sed '/^\('"$name"': \).*/s//\1'"$pass"'/' users.passwords > temp
mv temp users.passwords

Hi,

Thanks for your reply - that works fine.. Just one more question, if the entry in my file is like below,

Code:
export David=???
export Michael=password
export Frank=???

and I would wish to transform it to be like
Code:
export David=???
export Michael=new_password
export Frank=???

then how should I modify that sentence? Sorry I'm new to sed

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to find if any new entry in directory

I require a shell script to find if any new entry of dump files present in a particular directory and to send an email if any new entry exists.I had a crontab to run the script for every 5 min. Below are the file names.dump.20150327.152407.12058630.0002.phd.gz... (9 Replies)
Discussion started by: bhas85
9 Replies

2. Shell Programming and Scripting

Update config file using shell script in Solaris 5.10

hi I need to update the value in config.txt value using shell script example: lets say a value in config.txt file is as SEQUENCE=1 after some iteration as the loop ends , the SEQUENCE should get update in the config.txt file with a new value of SEQUENCE=2. also , can anyone please help me... (7 Replies)
Discussion started by: ravidwivedi2288
7 Replies

3. Shell Programming and Scripting

Shell script to update zone file

Hi folks, I have zone files at below path i want to modify their name i don't know how to do it, Can some can suggest some kind line technique. I give you detail I have domain ibphello.com host at ip address 10.2.2.1 and 50 plus domain are there /var/named/*.db. If i want to change... (0 Replies)
Discussion started by: learnbash
0 Replies

4. Shell Programming and Scripting

Shell script to read from a file and update remote server

Its a tough one and would appreciate any guidance for a script that i am trying to develop....Again I do understand its a complicated script and help would be greatly appreciated.... Thank you 1- Need to check for a file (in a certain location on a server) every 15 minute or so if it is there... (4 Replies)
Discussion started by: aavam
4 Replies

5. UNIX for Dummies Questions & Answers

How to Update DB table from txt file using CRONJOB in Unix Shell Script

Hi Experts, can guide how we can Update a Database Table using a txt file source Using Unix Shell Scripts. What are the Cron Jobs codes can written to Update DB table. txt file contains record like data. US 09/03/2012 User DocType DocID. these above feilds in txt files need to be updated in... (4 Replies)
Discussion started by: mahesh.sap
4 Replies

6. Shell Programming and Scripting

Script to update Property Entry Values

Hi All, I'm Raghavendra. I have a very urgent requirement to develop a Shell Script which will allow to use variables in a property file as demonstarted below var1=UNIX var2=LINUX var3=WINDOWS var4=$var1,$var2 var5=$var3 Could you please help me to develop a shell script which can... (2 Replies)
Discussion started by: raghavstunner
2 Replies

7. UNIX for Dummies Questions & Answers

update records in a file using shell script...

Hi, I have a file with 6 columns. First 3 columns together make unique record. I have a variable ($v) which hold a value that is obtained by a caliculaion. I have to replace value in 5th columnn with the value of the variable ($v). The value $v is caliculated from col4 and col6 values. ... (2 Replies)
Discussion started by: new_learner
2 Replies

8. Shell Programming and Scripting

update file contents using shell script

Hi, I am having a file which contains as below Names(aaaa ,bbbb ,cccc ,dddd) now i want the file to be updated with new value 'eeee' as below Names(aaaa ,bbbb ,cccc ,dddd ,eeee) Is there a way to script this ? Thanks, (5 Replies)
Discussion started by: drams
5 Replies

9. Shell Programming and Scripting

shell script to edit file and delete entry

Can anyone provide me a shell script to edit a xml file and delete one entry. To do manually i can edit(vi editor) the file and 'dd' will delete the file.But I wiluld to know if I can do with a script. Thanks in advance Tannu (6 Replies)
Discussion started by: tannu
6 Replies

10. Shell Programming and Scripting

Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it. Requirement: files are ftp to... (1 Reply)
Discussion started by: dba_nh
1 Replies
Login or Register to Ask a Question