Replacement of text in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacement of text in a file
# 1  
Old 02-09-2009
Java Replacement of text in a file

Hi ,

I have some data in my file(properties.txt) like this.

# agent.properties
agent.dmp.Location=
agent.name=

I need to relpace the
agent.dmp.location with agent.dmp.Location = /opt/VRTS/vxvm

I am using the follwing to replace the string

AGENT_NAME=snmp
AGENT_DMP_LOCATION=/var/opt
sed "s/agent.name=.*/agent.name= $AGENT_NAME/g" properties.txt > properties.txt.tmp;
mv properties.txt.tmp properties.txt > /dev/null 2>&1


the above command is successfully executing and the value in the file is

# agent.properties
agent.dmp.Location=snmp
agent.name=

but for agent.dmp.Location

sed "s/agent.dmp.Location=.*/agent.dmp.Location= $AGENT_DMP_LOCATION/g" properties.txt > properties.txt.tmp;
mv properties.txt.tmp properties.txt > /dev/null 2>&1


is showing error like this

sed: command garbled: s/agent.dmp.Location =.*/agent.dmp.Location= /var/opt/g

i think the problem is due the variable AGENT_DMP_LOCATION=/var/opt..since it has '/' .

could anyone please solve this issue.
thanks in advance.
raghu.amilineni
# 2  
Old 02-09-2009
That's because the shell sees your command as
Code:
sed "s/agent.dmp.Location=.*/agent.dmp.Location= /var/opt/g" properties.txt > properties.txt.tmp;

which is incorrect. Try writing your sed command as
Code:
sed "s|agent.dmp.Location=.*|agent.dmp.Location= $AGENT_DMP_LOCATION|g" properties.txt > properties.txt.tmp;

# 3  
Old 02-09-2009
Thanks Mr. Genius

It worked fine.
raghu.amilineni
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed text replacement

Hello, I'm using Bash and Sed to replace text within a text file (1.txt) twice in one script. Using a for loop I'm initially replacing any 'apple' words with the variable 'word1' ("leg). I'm then using another for loop to replace any 'apple' words with the variable 'word2' ("arm"). This task is... (2 Replies)
Discussion started by: Flip-Flop
2 Replies

2. Shell Programming and Scripting

Multiple Replacement in a Text File in one operation (sed/awk) ?

Hi all, Saying we have two files: 1. A "Reference File" whose content is "Variable Name": "Variable Value" 2. A "Model File" whose content is a model program in which I want to substitute "VariableName" with their respective value to produce a third file "Program File" which would be a... (4 Replies)
Discussion started by: dae
4 Replies

3. Shell Programming and Scripting

Text replacement with awk or sed?

Hi guys, I worked for almost a half-day for the replacement of some text automatically with script. But no success. The problem is I have hundred of files, which need to be replaced with some new text. It's a painful work to work manually and it's so easy to do it wrong. For example, I... (2 Replies)
Discussion started by: liuzhencc
2 Replies

4. Shell Programming and Scripting

Conditional replacement of columns in a text file

Hello scriping expert friends, I have 2 requirements on replacing fields of text files: I have lot of data with contents like below: Requirement-1: The digit after 0 should always be changed to 1 (3 Replies)
Discussion started by: magnus29
3 Replies

5. Shell Programming and Scripting

Block of text replacement using sed

Hi, I have a requirement in which i need to replace text as below - <stringProp name="Recipe">&lt;AddGroup Name=&quot;1001&quot; Path=&quot;ServiceAdministration/Controls/1001/ServiceSwitches&quot;&gt; &lt;Param Name=&quot;AttributeName&quot; Value=&quot;HeaderManipRspIngressRuleSet&quot; Type=&quot;String&quot; /&gt; &lt;Param Name=&quot;Value&quot;... (0 Replies)
Discussion started by: abhitanshu
0 Replies

6. UNIX for Dummies Questions & Answers

Simple awk script for positional replacement in text?

I have a string of letters. (They happen to be DNA, not that it's relevant to the question.) For analysis purposes, I need to replace the information at some of the sites. I need to do this based on their position, not the information in that position. I also need to ignore differences at other... (10 Replies)
Discussion started by: JFS
10 Replies

7. Shell Programming and Scripting

Replacing text based on replacement tables

Dear all, will be grateful for your advices.. The need is (i guess) simple for UNIX experts. Basically, there are replacement tables, which would be used to replace text strings in the data (large volumes..). An exmpl table (a "config file"): VIFIS1_1_PE1836 VIBRIO_FISCHERI VIPAR1_1_PE1662 ... (7 Replies)
Discussion started by: roussine
7 Replies

8. UNIX for Dummies Questions & Answers

Sed text replacement issue.

Hi, Im trying to find and replace text within a unix file using sed. The command that i have been using is sed '/,null,/ s//, ,/g' result.txt>result.tmp for replacing ",null," with ", ,". But this only replaces the first occurrance of ,null, in every line. I want to do it globally. It... (7 Replies)
Discussion started by: sohaibs
7 Replies

9. UNIX for Dummies Questions & Answers

Text replacement between 2 files

I have 2 files that are tab dilimiter: file1 contains: T 1 2 3 1000 T 5 10 15 9000 T 4 5 6 2000 T 3 7 9 6000 AND SO ON file2 contains: (columns number 1, 2, and 3 are match-pattern to file1) 1 2 3 JOHN 4 4 4 MIKE 4 5 6 TOM 3 7 9 MIKE AND SO ON I want file3 contains... (3 Replies)
Discussion started by: bobo
3 Replies

10. UNIX for Dummies Questions & Answers

Awk/Sed One liner for text replacement

Hi group, I want to replace the occurance of a particular text in a paragraph.I tried with Sed,but Sed only displays the result on the screen.How can i update the changes in the original file??? The solution should be a one liner using awk and sed. Thanks in advance. (5 Replies)
Discussion started by: bishnu.bhatta
5 Replies
Login or Register to Ask a Question