import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Sampleexpense {
private int i;
public static void main(String args[]) throws FileNotFoundException, IOException {
int i;
String[] substr;
String sub = null;
String res = null;
BufferedReader in = new BufferedReader(new FileReader("C:\\Documents and Settings\\abb\\Desktop\\test\\Invo.txt"));
StringBuffer sb = new StringBuffer();
String line;
line = in.readLine();
while (line != null) {
sb = sb.append(line);
line = in.readLine();
}
String line1 = sb.toString();
//System.out.println(line1);
sub = line1.substring(line1.indexOf("Value (Rs.)"), line1.indexOf("Gross Total"));
sub = sub.replace("Value (Rs.)", "");
// System.out.println("Sub String " + sub);
res = sub;
Matcher tabledata = Pattern.compile(("\\d*,\\d{3}"), Pattern.CASE_INSENSITIVE).matcher(sub);
i = 0;
while (tabledata.find()) {
i++;
}
String[] table = new String[i];
Matcher tdata = Pattern.compile(("\\d*,\\d{3}"), Pattern.CASE_INSENSITIVE).matcher(sub);
for (int ij = 0; ij < i; ij++) {
while (tdata.find()) {
table[ij] = tdata.group();
break;
}
}
String[] res1 = new String[i];
for (int ik = 0; ik < i; ik++) {
//System.out.println(" output " + table[ik]);
res1[ik] = String.valueOf(ik + 1);
}
for (int a = 0; a < i; a++) {
//System.out.println("Number "+(a+1)+" "+table[a]);
sub = sub.substring(sub.indexOf(res1[a]), sub.indexOf(table[a]));
System.out.println(" " + sub + table[a]);
res = res.replace(sub + table[a], "");
sub = res;
}
}
}