开发者

how can i filter whole line which contains a specific string

i have the following Ant script for reading re开发者_C百科visionlog.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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜