Computing.Net > Forums > Unix > Replacing values in a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Replacing values in a file

Reply to Message Icon

Name: amit4g
Date: February 1, 2007 at 00:20:04 Pacific
OS: hp-ux(11.23)
CPU/Ram: PA
Product: PA
Comment:

Hi,

how do we change a variable's value in a file?
e.g.
$ cat <file1>
AGE=1
bla bla...........

i need to change the value of variable "AGE" to a newvalue(let's say "0")

Thanks,
Amit



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 1, 2007 at 19:35:46 Pacific
Reply:

Hi:

We've been talking about gres:

http://www.computing.net/unix/wwwbo...

# gres
pattern=$1
replacement=$2

A="`echo | tr '\012' '\001' `"
sed -e "s$A$pattern$A$replacement$A" $3
# end script

Here is an example

gres "Age=0" "Age=1" filename


0
Reply to Message Icon

Related Posts

See More


cut 1 file to records Nested while loop



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Replacing values in a file

replace data in a file www.computing.net/answers/unix/replace-data-in-a-file/6189.html

how to replace a line in a file www.computing.net/answers/unix/how-to-replace-a-line-in-a-file/7214.html

AWK command to find 2 values in a f www.computing.net/answers/unix/awk-command-to-find-2-values-in-a-f/5853.html