You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Nehal Patel <ne...@gmail.com> on 2012/01/14 00:01:14 UTC

Update property value in file and retaining format.

Hello,
Having an problem updating the value of in a property file and
retaining the format.  For example i have the following
stuff.properties:
test1  <tab> <tab> <tab> =aaa
test2  <tab> <tab> <tab> =bbb
test3  <tab> <tab> <tab> =ccc


I run the following:
	<target name="update-stuff-properties">
		<replaceregexp file="stuff.properties"
			match="^[ \t]*test2[ \t]*=.*$"
			replace="test2=zzzzzzzz"
			byline="true"
		/>
	</target>


I get the following:
test1  <tab> <tab> <tab> =aaa
test2=zzzzzzzz
test3  <tab> <tab> <tab> =ccc


I must be missing something on how to retain the "  <tab> <tab> <tab>
" which proceed the "=".

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Update property value in file and retaining format.

Posted by Klaus Malorny <Kl...@knipp.de>.
On 18/01/12 17:46, Nehal Patel wrote:
> Nice, this was the solution!
> Frankly this is a bit more advanced that i know.
>
> I don't know the following:
> What the "^" means.
> What the "$" means.
> What the "\1" means.
>

All you want to know about regular expressions and even more:

   http://www.regular-expressions.info

Look at "Anchors" and "Grouping & Backreferences".


Regards,

Klaus



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Update property value in file and retaining format.

Posted by Emma Burrows <Em...@rpharms.com>.
Well answered, Harold. :) Regular expressions can be a little daunting when you first start looking at them, but they're very powerful once you've wrapped your head around how they work. And I'm finding that they pop up *everywhere* these days!


-----Original Message-----
From: Harold Putman [mailto:hputman@lexmark.com]
Sent: 18 January 2012 19:51
To: Ant Users List
Subject: Re: Update property value in file and retaining format.

These are Regular Expression "metacharacters"

^ means start of line
$ means end of line
\1 is a "backreference" used in substitution. It means insert the first
part of the pattern than matches.

If you Google or look up a book on Regular Expressions you will find more
complete explanations of these things.

-Harold

On Wed, Jan 18, 2012 at 11:46 AM, Nehal Patel <ne...@gmail.com>wrote:

> Nice, this was the solution!
> Frankly this is a bit more advanced that i know.
>
> I don't know the following:
> What the "^" means.
> What the "$" means.
> What the "\1" means.
>
>
> Thanks.
>
> On Mon, Jan 16, 2012 at 4:38 AM, Emma Burrows <Emma.Burrows@rpharms.com
> >wrote:
>
> > You're replacing the entire "Test2<tab><tab>=" line with the string
> > "test2=xxxxx" which obviously doesn't contain the tab characters.
> >
> > You should probably investigate more sophisticated ways of preserving the
> > original tabs like
> >
> > match="^([ \t]*test2[ \t]*=)(.*)$"
> > replace="\1xxxxxxx"
> >
> > I haven't tested it but something like that should preserve "test2" and
> > all the tabs around it, while still replacing the bit you actually want
> to
> > change, which is whatever comes after the = sign.
> >
> > HTH!
> >
> >
> > -----Original Message-----
> > From: Nehal Patel [mailto:nehalhpatel.ct@gmail.com]
> > Sent: 13 January 2012 23:01
> > To: user@ant.apache.org
> > Subject: Update property value in file and retaining format.
> >
> > Hello,
> > Having an problem updating the value of in a property file and
> > retaining the format.  For example i have the following
> > stuff.properties:
> > test1  <tab> <tab> <tab> =aaa
> > test2  <tab> <tab> <tab> =bbb
> > test3  <tab> <tab> <tab> =ccc
> >
> >
> > I run the following:
> >        <target name="update-stuff-properties">
> >                <replaceregexp file="stuff.properties"
> >                        match="^[ \t]*test2[ \t]*=.*$"
> >                        replace="test2=zzzzzzzz"
> >                        byline="true"
> >                />
> >        </target>
> >
> >
> > I get the following:
> > test1  <tab> <tab> <tab> =aaa
> > test2=zzzzzzzz
> > test3  <tab> <tab> <tab> =ccc
> >
> >
> > I must be missing something on how to retain the "  <tab> <tab> <tab>
> > " which proceed the "=".
> >
> > Thanks.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
> > ______________________________________________________________________
> > This email has been scanned by the Symantec Email Security.cloud service.
> > For more information please visit http://www.symanteccloud.com
> > ______________________________________________________________________
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>



--
Harold PUTMAN
Web Technology Specialist
*Lexmark International, Inc. <http://www.lexmark.com>*
740 W New Circle Rd.
Lexington, KY 40550
+1(859) 232-2839
hputman@lexmark.com


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Update property value in file and retaining format.

Posted by Harold Putman <hp...@lexmark.com>.
These are Regular Expression "metacharacters"

^ means start of line
$ means end of line
\1 is a "backreference" used in substitution. It means insert the first
part of the pattern than matches.

If you Google or look up a book on Regular Expressions you will find more
complete explanations of these things.

-Harold

On Wed, Jan 18, 2012 at 11:46 AM, Nehal Patel <ne...@gmail.com>wrote:

> Nice, this was the solution!
> Frankly this is a bit more advanced that i know.
>
> I don't know the following:
> What the "^" means.
> What the "$" means.
> What the "\1" means.
>
>
> Thanks.
>
> On Mon, Jan 16, 2012 at 4:38 AM, Emma Burrows <Emma.Burrows@rpharms.com
> >wrote:
>
> > You're replacing the entire "Test2<tab><tab>=" line with the string
> > "test2=xxxxx" which obviously doesn't contain the tab characters.
> >
> > You should probably investigate more sophisticated ways of preserving the
> > original tabs like
> >
> > match="^([ \t]*test2[ \t]*=)(.*)$"
> > replace="\1xxxxxxx"
> >
> > I haven't tested it but something like that should preserve "test2" and
> > all the tabs around it, while still replacing the bit you actually want
> to
> > change, which is whatever comes after the = sign.
> >
> > HTH!
> >
> >
> > -----Original Message-----
> > From: Nehal Patel [mailto:nehalhpatel.ct@gmail.com]
> > Sent: 13 January 2012 23:01
> > To: user@ant.apache.org
> > Subject: Update property value in file and retaining format.
> >
> > Hello,
> > Having an problem updating the value of in a property file and
> > retaining the format.  For example i have the following
> > stuff.properties:
> > test1  <tab> <tab> <tab> =aaa
> > test2  <tab> <tab> <tab> =bbb
> > test3  <tab> <tab> <tab> =ccc
> >
> >
> > I run the following:
> >        <target name="update-stuff-properties">
> >                <replaceregexp file="stuff.properties"
> >                        match="^[ \t]*test2[ \t]*=.*$"
> >                        replace="test2=zzzzzzzz"
> >                        byline="true"
> >                />
> >        </target>
> >
> >
> > I get the following:
> > test1  <tab> <tab> <tab> =aaa
> > test2=zzzzzzzz
> > test3  <tab> <tab> <tab> =ccc
> >
> >
> > I must be missing something on how to retain the "  <tab> <tab> <tab>
> > " which proceed the "=".
> >
> > Thanks.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
> > ______________________________________________________________________
> > This email has been scanned by the Symantec Email Security.cloud service.
> > For more information please visit http://www.symanteccloud.com
> > ______________________________________________________________________
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>



-- 
Harold PUTMAN
Web Technology Specialist
*Lexmark International, Inc. <http://www.lexmark.com>*
740 W New Circle Rd.
Lexington, KY 40550
+1(859) 232-2839
hputman@lexmark.com

Re: Update property value in file and retaining format.

Posted by Nehal Patel <ne...@gmail.com>.
Nice, this was the solution!
Frankly this is a bit more advanced that i know.

I don't know the following:
What the "^" means.
What the "$" means.
What the "\1" means.


Thanks.

On Mon, Jan 16, 2012 at 4:38 AM, Emma Burrows <Em...@rpharms.com>wrote:

> You're replacing the entire "Test2<tab><tab>=" line with the string
> "test2=xxxxx" which obviously doesn't contain the tab characters.
>
> You should probably investigate more sophisticated ways of preserving the
> original tabs like
>
> match="^([ \t]*test2[ \t]*=)(.*)$"
> replace="\1xxxxxxx"
>
> I haven't tested it but something like that should preserve "test2" and
> all the tabs around it, while still replacing the bit you actually want to
> change, which is whatever comes after the = sign.
>
> HTH!
>
>
> -----Original Message-----
> From: Nehal Patel [mailto:nehalhpatel.ct@gmail.com]
> Sent: 13 January 2012 23:01
> To: user@ant.apache.org
> Subject: Update property value in file and retaining format.
>
> Hello,
> Having an problem updating the value of in a property file and
> retaining the format.  For example i have the following
> stuff.properties:
> test1  <tab> <tab> <tab> =aaa
> test2  <tab> <tab> <tab> =bbb
> test3  <tab> <tab> <tab> =ccc
>
>
> I run the following:
>        <target name="update-stuff-properties">
>                <replaceregexp file="stuff.properties"
>                        match="^[ \t]*test2[ \t]*=.*$"
>                        replace="test2=zzzzzzzz"
>                        byline="true"
>                />
>        </target>
>
>
> I get the following:
> test1  <tab> <tab> <tab> =aaa
> test2=zzzzzzzz
> test3  <tab> <tab> <tab> =ccc
>
>
> I must be missing something on how to retain the "  <tab> <tab> <tab>
> " which proceed the "=".
>
> Thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
> ______________________________________________________________________
> This email has been scanned by the Symantec Email Security.cloud service.
> For more information please visit http://www.symanteccloud.com
> ______________________________________________________________________
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

RE: Update property value in file and retaining format.

Posted by Emma Burrows <Em...@rpharms.com>.
You're replacing the entire "Test2<tab><tab>=" line with the string "test2=xxxxx" which obviously doesn't contain the tab characters.

You should probably investigate more sophisticated ways of preserving the original tabs like

match="^([ \t]*test2[ \t]*=)(.*)$"
replace="\1xxxxxxx"

I haven't tested it but something like that should preserve "test2" and all the tabs around it, while still replacing the bit you actually want to change, which is whatever comes after the = sign.

HTH!


-----Original Message-----
From: Nehal Patel [mailto:nehalhpatel.ct@gmail.com]
Sent: 13 January 2012 23:01
To: user@ant.apache.org
Subject: Update property value in file and retaining format.

Hello,
Having an problem updating the value of in a property file and
retaining the format.  For example i have the following
stuff.properties:
test1  <tab> <tab> <tab> =aaa
test2  <tab> <tab> <tab> =bbb
test3  <tab> <tab> <tab> =ccc


I run the following:
        <target name="update-stuff-properties">
                <replaceregexp file="stuff.properties"
                        match="^[ \t]*test2[ \t]*=.*$"
                        replace="test2=zzzzzzzz"
                        byline="true"
                />
        </target>


I get the following:
test1  <tab> <tab> <tab> =aaa
test2=zzzzzzzz
test3  <tab> <tab> <tab> =ccc


I must be missing something on how to retain the "  <tab> <tab> <tab>
" which proceed the "=".

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org