Piyush
Piyush

Reputation: 5315

how can i filter whole line which contains a specific string

i have the following Ant script for reading revisionlog.txt file line by line and printing all the line.

<target name="line_by_line">
   <loadfile property="file" srcfile="revisionlog.txt"/>
   <for param="line" list="${file}" delimiter="${line.separator}">
      <sequential>
         <echo>@{line}</echo>       
     </sequential>
   </for>
</target>

but here i want to print those line only which contains Comments: string. how can i do this.

Upvotes: 1

Views: 4625

Answers (1)

Rebse
Rebse

Reputation: 10377

you may use loadfile combined with a filterchain, f.e. :

<loadfile property="yourline" srcfile="revisionlog.txt">
  <filterchain>
    <linecontains>
      <contains value="Comments:"></contains>
    </linecontains>
  </filterchain>
</loadfile>

<echo>$${yourline} = ${line.separator}${yourline}</echo>

if you need more control, use <linecontainsregexp>
see Ant manual for FilterChains and FilterReaders

Upvotes: 3

Related Questions