• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

replace word in file

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The replacetoken filterchain item might work.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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" />
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic