ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Remove a specific line from a file.
Date Wed, 12 Nov 2003 15:18:23 GMT
> From: peter reilly [mailto:peter.reilly@corvil.com]
> Sent: Wednesday, November 12, 2003 2:56 AM
> To: Ant Users List
> Subject: Re: Remove a specific line from a file.
> 
> On Wednesday 12 November 2003 07:22, Stefan Bodewig wrote:
> > On Tue, 11 Nov 2003, Robert Priest <Robert.Priest@bentley.com> wrote:
> > > Can anyone tell me how to remove a specific line from a text file
> > > using ant.
> >
> > <replaceregexp> would probably work - simply replace the line your
> > don't want to see with nothing.
> >
> > Ant 1.6beta with a <linecontainsregexp> filterreader in <copy> would
> > work as well - you'd jave to craft a regexp that matched all your
> > lines except for the one you don't want to see in your file.
> 
> Ant 1.6beta also has a <scriptfilter> which allows you to write
> a filter as follows:
>     <concat>
>       This is a line
>       this is a bad line
>       This is a good line
>       <filterchain>
>         <scriptfilter language="beanshell">
>           if (self.getToken().indexOf("good") == -1) {
>              self.setToken(null);
>           }
>         </scriptfilter>
>       </filterchain>
>     </concat>
> 
> With java 1.4 one may use a regex:
> 
>         <scriptfilter language="beanshell">
>           if (!self.getToken().matches(".*This.*good.*line.*")) {
>               self.setToken(null);
>           }
>         </scriptfilter>

I've been using myself a homegrown <sed> task. Here's an example:

    <bm:sedEditorGroup id="pmodel - fix flex/bison">
      <delete  pattern="^# *line" />
      <delete  pattern="^# *[0-9]" />
      <replace pattern="yy" with="yy_pmodel_gram_" />
      <replace pattern="__EXTERN_C__" with="__cplusplus" />
    </bm:sedEditorGroup>

        <bm:sed from="pmodel/pmodel_gram_tab.c"
                  to="pmodel/pmodel_gram.y.cpp">
          <editorGroup refid="pmodel - fix flex/bison" />
        </bm:sed>
        <bm:sed from="pmodel/pmodel_gram_tab.h"
                  to="pmodel/pmodel_gram.y.h">
          <editorGroup refid="pmodel - fix flex/bison" />
        </bm:sed>

I find this more straightforward. --DD

PS: For info, here's the full context of its use:

    <ac:outofdate>
      <sourcefiles>
        <pathelement location="script/cgram.y" />
      </sourcefiles>
      <targetfiles>
        <pathelement location="script/cgram.y.cpp" />
        <pathelement location="script/cgram.y.h" />
      </targetfiles>
      <sequential>
        <echo>Bisoning script/cgram.y...</echo>
        <exec executable="${bison}" failonerror="true">
          <arg value="-vd" />
          <arg value="-o" />
          <arg file="script/cgram_tab.c" />
          <arg file="script/cgram.y" />
          <env key="BISON_SIMPLE" value="${tools.dir}/bin/bison.simple" />
        </exec>
        <bm:sed from="script/cgram_tab.c" to="script/cgram.y.cpp">
          <editorGroup refid="script - fix flex/bison" />
        </bm:sed>
        <bm:sed from="script/cgram_tab.h" to="script/cgram.y.h">
          <editorGroup refid="script - fix flex/bison" />
        </bm:sed>
        <delete file="script/cgram.out" />
        <delete file="script/cgram.output" />
        <delete file="script/cgram_tab.c" />
        <delete file="script/cgram_tab.h" />
      </sequential>
    </ac:outofdate>

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


Mime
View raw message