![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk - replace number of string length from search and replace for a serialized array | otrotipo | Shell Programming and Scripting | 1 | 07-10-2009 12:04 PM |
| Search, replace string in file1 with string from (lookup table) file2? | gstuart | Shell Programming and Scripting | 9 | 06-08-2009 06:11 AM |
| Search for a string and replace the searched string in the same position in samefile | ganesh_248 | UNIX for Dummies Questions & Answers | 27 | 03-23-2009 12:35 AM |
| sed - replace string question | danmero | Shell Programming and Scripting | 4 | 01-04-2008 02:28 PM |
| How to replace all string instances found by find+grep | umen | Shell Programming and Scripting | 0 | 12-06-2007 03:52 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
sed/grep string replace question
Hi all,
I know this question has probably been answered before, but I am struggling with this problem, even after googling a million pages. In a file named rdmt.conf I need a single character replaced, the number in the line below CUR_OC4J_ID=1 It will always appear after CUR_OC4J_ID in the file. ie replaced by: CUR_OC4J_ID=2 I need to be able to toggle this value a few times in my script. I can find the character via a grep: CUR_OC4J_ID=$(grep CUR_OC4J_ID $SCRIPTDIR/rdmt.conf | cut -d= -f2) But I cant work out how to replace it. I have even created some test files. I can use the sed command to replace "hello" with "no" in a file, but when it gets to CUR_OC4J_ID it just spits out text saying the number in which i wanted it replaced to, and then when you look at the file, its not changed. I thought I could make it easier (but not neater) and just find the current value, and replace the whole line because I can put a variable in the sed command...... Any help would be appreciated, I know this is easy, but I have googled forever. A sed command that doesn't depend on what number is after CUR_OC4J_ID would be the best/neatest solution. |
|
||||
|
Alternatively you can also use sed. If your sed knows the -i option you can change the value in the file like this
Code:
newval=2 sed -i "s/\(CUR_OC4J_ID=\).*/\1$newval/" rdmt.conf Code:
sed "s/\(CUR_OC4J_ID=\).*/\1$newval/" rdmt.conf > rdmt.conf.new && mv -f rdmt.conf.new rdmt.conf |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|