[use case] Grep

Description

The Grep use case illustrates the txt task in a file2file usage : grep txt datas to txt.

Sample

Transform txt datas to txt with grep function.

$ tree --charset=ascii grep/
grep/
|-- build.xml
|-- gen
|   `-- grep.txt
|-- datas
|   `-- file.txt
`-- templates
    `-- grep.ftl

ant file - build.xml

<project name="usecases" xmlns:bj="antlib:org.bidji.taskdefs">
  <target name="grep" description="grep">       
    <bj:txtt file="datas/file.txt" tofile="gen/grep.txt" template="templates/grep.ftl" overwrite="true"/>
  </target>
</project>

input file - file.txt

line1 aaa
line2 bbb
line3 aaa

grep.ftl

### VALUES
[#foreach line in txt?api.lines()]
${line}
[/#foreach]

### GREP WITH txtt 'grep'
[#foreach line in txt?api.grep('aaa')]
${line}
[/#foreach]

### GREP WITH freemarker 'contains'
[#foreach line in txt?api.lines()]
[#if line?contains('aaa')]
${line}
[/#if]
[/#foreach]

grep.txt

### VALUES
line1 aaa
line2 bbb
line3 aaa

### GREP WITH txtt 'grep'
line1 aaa
line3 aaa

### GREP WITH freemarker 'contains'
line1 aaa
line3 aaa