Replace string in file

View: New views
8 Messages — Rating Filter:   Alert me  

Replace string in file

by Guy Catz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hey guys,
 
Is it possible to replace a string in an existing file?
 
Thanks,
    Guy.

RE: Replace string in file

by Sean Tiley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have a look at the ReplaceRegExp and Replace tasks

Should be what you are looking for.

-----Original Message-----
From: Guy Catz [mailto:Guy.catz@...]
Sent: Monday, May 12, 2008 9:18 AM
To: user@...
Subject: Replace string in file

hey guys,
 
Is it possible to replace a string in an existing file?
 
Thanks,
    Guy.

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


Re: Replace string in file

by David Weintraub :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What type of replacement? You can do a filter on strings like
@VERSION@, @DATE@, @FOO@, or whatever you want via filtersets and
mappers when you copy. For example, I have some configuration files.
They're called *.properties.template, and I replace the @xxx@ strings
with values from a deploy.properties file and remove the *.template
suffix. The filterset replaces the @xxx@ tokens with the correct
values while the mapper renames the file by removing the *.template
suffix:

        <!-- Copy the configuration files that don't contain tokens -->
        <copy todir="${local.jboss.home}/server/${jboss.instance}"
            verbose="${copy.verbose.flag}">
            <fileset dir="${jboss.install.home}/jbdev1">
                <exclude name="**/*.template"/>
            </fileset>
        </copy>

        <!-- Copy the configurable files and replace any tokens -->
        <copy todir="${local.jboss.home}/server/${jboss.instance}"
            overwrite="true"
            verbose="${copy.verbose.flag}">
            <fileset dir="${jboss.install.home}/jbdev1">
                <include name="**/*.template"/>
            </fileset>
            <mapper type="glob"
                from="*.template" to="*"/>
            <filterset begintoken="@" endtoken="@">
                <filter token="path_to_server_dir"
                    value="${local.jboss.home}/server/${jboss.instance}"/>
                <filtersfile file="${deploy.properties.file}"/>
            </filterset>
        </copy>

Is this what you're looking for?

On Mon, May 12, 2008 at 9:18 AM, Guy Catz <Guy.catz@...> wrote:
> hey guys,
>
>  Is it possible to replace a string in an existing file?
>
>  Thanks,
>     Guy.
>



--
--
David Weintraub
qazwart@...

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


RE: Replace string in file

by Guy Catz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the answer.

I need to replace @token@ with <aa><bb></bb></aa>.
But the ANT engine tells me that I can't use '<' or '>'.

Please advice.

Thanks.

-----Original Message-----
From: David Weintraub [mailto:qazwart@...]
Sent: Tuesday, May 13, 2008 8:27 PM
To: Ant Users List
Subject: Re: Replace string in file

What type of replacement? You can do a filter on strings like @VERSION@,
@DATE@, @FOO@, or whatever you want via filtersets and mappers when you
copy. For example, I have some configuration files.
They're called *.properties.template, and I replace the @xxx@ strings
with values from a deploy.properties file and remove the *.template
suffix. The filterset replaces the @xxx@ tokens with the correct values
while the mapper renames the file by removing the *.template
suffix:

        <!-- Copy the configuration files that don't contain tokens -->
        <copy todir="${local.jboss.home}/server/${jboss.instance}"
            verbose="${copy.verbose.flag}">
            <fileset dir="${jboss.install.home}/jbdev1">
                <exclude name="**/*.template"/>
            </fileset>
        </copy>

        <!-- Copy the configurable files and replace any tokens -->
        <copy todir="${local.jboss.home}/server/${jboss.instance}"
            overwrite="true"
            verbose="${copy.verbose.flag}">
            <fileset dir="${jboss.install.home}/jbdev1">
                <include name="**/*.template"/>
            </fileset>
            <mapper type="glob"
                from="*.template" to="*"/>
            <filterset begintoken="@" endtoken="@">
                <filter token="path_to_server_dir"
 
value="${local.jboss.home}/server/${jboss.instance}"/>
                <filtersfile file="${deploy.properties.file}"/>
            </filterset>
        </copy>

Is this what you're looking for?

On Mon, May 12, 2008 at 9:18 AM, Guy Catz <Guy.catz@...> wrote:
> hey guys,
>
>  Is it possible to replace a string in an existing file?
>
>  Thanks,
>     Guy.
>



--
--
David Weintraub
qazwart@...

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



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


AW: Replace string in file

by Jan.Materne :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You have to mask that like everywhere in XML.

Jan

> -----Ursprüngliche Nachricht-----
> Von: Guy Catz [mailto:Guy.catz@...]
> Gesendet: Donnerstag, 15. Mai 2008 15:17
> An: Ant Users List
> Betreff: RE: Replace string in file
>
> Thanks for the answer.
>
> I need to replace @token@ with <aa><bb></bb></aa>.
> But the ANT engine tells me that I can't use '<' or '>'.
>
> Please advice.
>
> Thanks.
>
> -----Original Message-----
> From: David Weintraub [mailto:qazwart@...]
> Sent: Tuesday, May 13, 2008 8:27 PM
> To: Ant Users List
> Subject: Re: Replace string in file
>
> What type of replacement? You can do a filter on strings like
> @VERSION@,
> @DATE@, @FOO@, or whatever you want via filtersets and
> mappers when you
> copy. For example, I have some configuration files.
> They're called *.properties.template, and I replace the @xxx@ strings
> with values from a deploy.properties file and remove the *.template
> suffix. The filterset replaces the @xxx@ tokens with the
> correct values
> while the mapper renames the file by removing the *.template
> suffix:
>
>         <!-- Copy the configuration files that don't contain
> tokens -->
>         <copy todir="${local.jboss.home}/server/${jboss.instance}"
>             verbose="${copy.verbose.flag}">
>             <fileset dir="${jboss.install.home}/jbdev1">
>                 <exclude name="**/*.template"/>
>             </fileset>
>         </copy>
>
>         <!-- Copy the configurable files and replace any tokens -->
>         <copy todir="${local.jboss.home}/server/${jboss.instance}"
>             overwrite="true"
>             verbose="${copy.verbose.flag}">
>             <fileset dir="${jboss.install.home}/jbdev1">
>                 <include name="**/*.template"/>
>             </fileset>
>             <mapper type="glob"
>                 from="*.template" to="*"/>
>             <filterset begintoken="@" endtoken="@">
>                 <filter token="path_to_server_dir"
>  
> value="${local.jboss.home}/server/${jboss.instance}"/>
>                 <filtersfile file="${deploy.properties.file}"/>
>             </filterset>
>         </copy>
>
> Is this what you're looking for?
>
> On Mon, May 12, 2008 at 9:18 AM, Guy Catz <Guy.catz@...> wrote:
> > hey guys,
> >
> >  Is it possible to replace a string in an existing file?
> >
> >  Thanks,
> >     Guy.
> >
>
>
>
> --
> --
> David Weintraub
> qazwart@...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@... For additional
> commands, e-mail: user-help@...
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

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


Re: Replace string in file

by David Weintraub :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, May 15, 2008 at 9:17 AM, Guy Catz <Guy.catz@...> wrote:
> Thanks for the answer.
>
> I need to replace @token@ with <aa><bb></bb></aa>.
> But the ANT engine tells me that I can't use '<' or '>'.

You have to escape those with "<" and ">" for "<" and ">"
respectively. The build.xml file is a XML file, and in XML the greater
and less than signs have special meanings.

Another possibility is to use a *.properties file for the replacement
string. Imagine having a file called "replace.properties" with this
line.

token=<aa><bb></bb></aa>

This is legal in properties files and should work when reading it with
ant. You can use a <filtersfile> as my example above shows. In the
above example, I have a file called "${deploy.properties.file}" that
contains the tokens I want to filter.

>
> Please advice.
>
> Thanks.
>
> -----Original Message-----
> From: David Weintraub [mailto:qazwart@...]
> Sent: Tuesday, May 13, 2008 8:27 PM
> To: Ant Users List
> Subject: Re: Replace string in file
>
> What type of replacement? You can do a filter on strings like @VERSION@,
> @DATE@, @FOO@, or whatever you want via filtersets and mappers when you
> copy. For example, I have some configuration files.
> They're called *.properties.template, and I replace the @xxx@ strings
> with values from a deploy.properties file and remove the *.template
> suffix. The filterset replaces the @xxx@ tokens with the correct values
> while the mapper renames the file by removing the *.template
> suffix:
>
>        <!-- Copy the configuration files that don't contain tokens -->
>        <copy todir="${local.jboss.home}/server/${jboss.instance}"
>            verbose="${copy.verbose.flag}">
>            <fileset dir="${jboss.install.home}/jbdev1">
>                <exclude name="**/*.template"/>
>            </fileset>
>        </copy>
>
>        <!-- Copy the configurable files and replace any tokens -->
>        <copy todir="${local.jboss.home}/server/${jboss.instance}"
>            overwrite="true"
>            verbose="${copy.verbose.flag}">
>            <fileset dir="${jboss.install.home}/jbdev1">
>                <include name="**/*.template"/>
>            </fileset>
>            <mapper type="glob"
>                from="*.template" to="*"/>
>            <filterset begintoken="@" endtoken="@">
>                <filter token="path_to_server_dir"
>
> value="${local.jboss.home}/server/${jboss.instance}"/>
>                <filtersfile file="${deploy.properties.file}"/>
>            </filterset>
>        </copy>
>
> Is this what you're looking for?
>
> On Mon, May 12, 2008 at 9:18 AM, Guy Catz <Guy.catz@...> wrote:
>> hey guys,
>>
>>  Is it possible to replace a string in an existing file?
>>
>>  Thanks,
>>     Guy.
>>
>
>
>
> --
> --
> David Weintraub
> qazwart@...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@... For additional
> commands, e-mail: user-help@...
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>



--
--
David Weintraub
qazwart@...

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


Re: Replace string in file

by Raja Nagendra Kumar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Use replace task

              <replace file="@{lFileName}"
                             token="ANT_TOKEN_IMAGES_ROOT_DIR"
                             value="${IMAGES_ROOT}"/>

Regards,
Nagendra

Re: Replace string in file

by AparnaSDoshi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Use replaceregexp  task with replacing < by 'ampersand sign lt semicolon' and > by 'ampersand sign gt semicolon'

<replaceregexp  file="filename" match="<a/>" replace=" " flags="g" byline="true"/>

Raja Nagendra Kumar wrote:
Use replace task

              <replace file="@{lFileName}"
                             token="ANT_TOKEN_IMAGES_ROOT_DIR"
                             value="${IMAGES_ROOT}"/>

Regards,
Nagendra