Nanu
Nanu

Reputation: 1

Merge multiple text files line by line using ANT

How do I merge multiple text files into one file. I want to read text line by line from each file and then merged text into the final output file. Sample text in my files are:

File 1 :

  aaa  
  bbb  
  ccc  

File 2 :

  ddd  
  eee  
  fff  

File 3 :

  ggg  
  hhh  
  iii  

Expected Output:

  aaa  -->from file 1
  ddd  -->from file 2
  ggg  -->from file 3
  bbb  
  eee  
  hhh  
  ccc  
  fff  
  iii 

I have tried the target below

<target name="mergeappvars" >  
    <concat destfile="${out.dir}/ApplicationGV.txt" force="no">  
        <fileset dir="${work.dir}/application"  
     includes="*.txt"/>  
    </concat>  
</target>

My logic is appending one file after another and I got the output as

aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii

Upvotes: 0

Views: 779

Answers (1)

Atul
Atul

Reputation: 1566

You need to write your own logic. This link will help you how to load a file and read from file using ant. How to read data line by line from a file using ant script?

Upvotes: 0

Related Questions