Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

replace word in file

 
kumar hai
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.Using ANT scripts i need to replace the one word location from particular files

example:
file:test.txt

55 <name>user.name.family</name>
56 </user-attribute>
57 </portlet-app>

123 <name>user.name.given</name>
124 </user-attribute>
125


In above i mention few line details ,there line no:57 (</porlet-app>) this line i need to replace to line no:125

i need to remove from 57 line,paste to line no:125.

Please help for this...

suresh

 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, but I did not follow your description. Perhaps if you showed the expected output file contents that would help.

Usually, to replace text in a file you use the copy task with a filterchain. For example, I often use generic config files that look like this:



Then I use this copy statement:



Then by setting the my.value property I get a new file with the desired value; example, entering:

ant -Dmy.value=foobar

yields:



There are many more filters you can use in a filter chain, see the Ant docs at http://ant.apache.org/manual/CoreTypes/filterchain.html
 
kumar hai
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply...


I want to replace one particular text (this text available in middle of one file.so i want to replace to end(last) . from one line to another line...

please arrange me sample scripts for this........

 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The replacetoken filterchain item might work.
 
Vijay Rajendran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to replace a word in a file using ANT script.

For Ex : Let's consider there is a line

"I like Apple" , in this line I'd like to replace the word "Apple" with "Orange" i.e the expected output should be "I like Orange".

This should be done using ANT script, any help is much appreciated.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay Rajendran wrote:This should be done using ANT script, any help is much appreciated.

So ... have you tried all that was discussed in the earlier posts?
 
Vijay Rajendran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the previous method, but I found the below one much more easier to replace,

<replace file="${file}" token="Apple" value="Orange" />
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic