You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Rebhan, Gilbert" <Gi...@huk-coburg.de> on 2005/01/26 14:31:13 UTC
putting value in txtfile
Hi,
yet another txtfileprocessing question.
File looks like that :
01 bla
02 bla
03 bla
04
05
06
07 bla
08 bla
09 bla
How to put the value of a property on line 4 ?
The rest of the file should remain as it is.
Problem : no tokens like @...@ there, just a blank line
The linenumber, where the value should be put in is always
line number 04.
Any hints ?
Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: putting value in txtfile
Posted by Matt Benson <gu...@yahoo.com>.
--- Erik Hatcher <er...@ehatchersolutions.com> wrote:
> Um.... nevermind..... I missed the part that there
> is "just a blank
> line". A custom FilterReader would work - have it
> only affect the 4th
> line.
>
> Erik
All you have to match is the line break count, so
assuming you know what those are (use fixcrlf worst
case) tokenfilter + filetokenizer + replaceregex
works. My self-contained example (with Jakarta ORO as
my regexp engine):
<project>
<property name="br" value="${line.separator}" />
<property name="insert" value="hello world" />
<echo file="foo.txt" append="false">01
bla${br}</echo>
<echo file="foo.txt" append="true">02
bla${br}</echo>
<echo file="foo.txt" append="true">03
bla${br}</echo>
<echo file="foo.txt" append="true">04 ${br}</echo>
<echo file="foo.txt" append="true">05 ${br}</echo>
<echo file="foo.txt" append="true">06 ${br}</echo>
<echo file="foo.txt" append="true">07
bla${br}</echo>
<echo file="foo.txt" append="true">08
bla${br}</echo>
<echo file="foo.txt" append="true">09
bla${br}</echo>
<copy file="foo.txt" tofile="bar.txt">
<filterchain>
<tokenfilter>
<filetokenizer />
<replaceregex
pattern="^(.*${br}.*${br}.*${br}.*)(${br}.*)"
replace="\1${insert}\2" />
</tokenfilter>
</filterchain>
</copy>
</project>
-Matt
__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: putting value in txtfile
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Um.... nevermind..... I missed the part that there is "just a blank
line". A custom FilterReader would work - have it only affect the 4th
line.
Erik
On Jan 26, 2005, at 8:55 AM, Erik Hatcher wrote:
> <replaceregexp> task or the replaceregex filter reader on a <copy>
> would do the trick, I think.
>
> Erik
>
>
> On Jan 26, 2005, at 8:31 AM, Rebhan, Gilbert wrote:
>
>>
>> Hi,
>>
>> yet another txtfileprocessing question.
>>
>> File looks like that :
>>
>> 01 bla
>> 02 bla
>> 03 bla
>> 04
>> 05
>> 06
>> 07 bla
>> 08 bla
>> 09 bla
>>
>> How to put the value of a property on line 4 ?
>>
>> The rest of the file should remain as it is.
>>
>> Problem : no tokens like @...@ there, just a blank line
>> The linenumber, where the value should be put in is always
>> line number 04.
>>
>> Any hints ?
>>
>> Gilbert
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: putting value in txtfile
Posted by Ninju Bohra <ni...@yahoo.com>.
You might want to read up on the <concat> task along with the <filterchain> nested elements.
One route...
Write your property out to a temp file
Use the <concant> along with <filterchain> sub-element to concat the first 3 lines of the orginal file with the temp file (stored in another file).
Then use another <concat> (with <filterchain> sub-element) to take the 4 line temp file and join it to the rest of the main file (i.e. the 5th line and beyond).
Erik Hatcher <er...@ehatchersolutions.com> wrote:
task or the replaceregex filter reader on a
would do the trick, I think.
Erik
On Jan 26, 2005, at 8:31 AM, Rebhan, Gilbert wrote:
>
> Hi,
>
> yet another txtfileprocessing question.
>
> File looks like that :
>
> 01 bla
> 02 bla
> 03 bla
> 04
> 05
> 06
> 07 bla
> 08 bla
> 09 bla
>
> How to put the value of a property on line 4 ?
>
> The rest of the file should remain as it is.
>
> Problem : no tokens like @...@ there, just a blank line
> The linenumber, where the value should be put in is always
> line number 04.
>
> Any hints ?
>
> Gilbert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
---------------------------------
Do you Yahoo!?
Yahoo! Search presents - Jib Jab's 'Second Term'
Re: putting value in txtfile
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
<replaceregexp> task or the replaceregex filter reader on a <copy>
would do the trick, I think.
Erik
On Jan 26, 2005, at 8:31 AM, Rebhan, Gilbert wrote:
>
> Hi,
>
> yet another txtfileprocessing question.
>
> File looks like that :
>
> 01 bla
> 02 bla
> 03 bla
> 04
> 05
> 06
> 07 bla
> 08 bla
> 09 bla
>
> How to put the value of a property on line 4 ?
>
> The rest of the file should remain as it is.
>
> Problem : no tokens like @...@ there, just a blank line
> The linenumber, where the value should be put in is always
> line number 04.
>
> Any hints ?
>
> Gilbert
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org