I have millions of files in a folder. File types will be with the name PES_timestamp and DOM_timestamp. I have to aggregate all PES and DOM filenames into one file which has the same filename.
The Aggregator program picks up only matching PES and DOM file pairs based on the timestamp of the file name from the incoming folder.
Example:
pes234343440
dom234343440
I thought of this idea to create 3 lists:
- Holds all files in the folder
- Holds only PES files
- Holds all DOM files
Finally, I will read all the file name from list and aggregate them from this program:
public void mergeFiles(File output,List<String> list) throws IOException {
BufferedWriter writer=null;
BufferedReader br = null;
BufferedReader r = null;
try {
writer = new BufferedWriter(new FileWriter(output));
for(int i=0;i<list.size();i++){
br = new BufferedReader(new FileReader("INCOMINGFOLDER/"+list.get(0)));
AggregateNj obj=new AggregateNj();
String s1 =null;
while ((s1 = br.readLine()) != null) {
writer.write(s1);
writer.write("\n");
}
}
} catch (IOException e){
e.printStackTrace();
}finally{
if(br != null)br.close();
if(r != null)r.close();
if(writer != null)writer.close();
}
}
Is this approach correct, or can you suggest a better approach?
bash
):cd /path/to/dir; for i in pes*; do cat $i ${i/pes/dom} > /path/to/dest/${i/pes/combined}; done
\$\endgroup\$