Grep.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.data.util;
00002
00003 import java.io.BufferedReader;
00004 import java.io.BufferedWriter;
00005 import java.io.FileInputStream;
00006 import java.io.FileOutputStream;
00007 import java.io.IOException;
00008 import java.io.InputStreamReader;
00009 import java.io.OutputStreamWriter;
00010 import java.util.regex.Matcher;
00011 import java.util.regex.Pattern;
00012
00013
00014
00015
00016
00017
00018 public class Grep
00019 {
00020
00029 static public void grep(String fin, String fout, String pattern, boolean shouldMatch)
00030 throws IOException
00031 {
00032
00033 removeMetrics(fin, fout);
00034 }
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 private static void removeMetrics(String fin, String fout)
00046 throws IOException
00047 {
00048
00049
00050 final BufferedReader inputFile = new BufferedReader(new InputStreamReader(new FileInputStream(fin)));
00051 final BufferedWriter outputFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fout)));
00052
00053 Pattern metricTag = Pattern.compile("<M ");
00054 Matcher matcher = metricTag.matcher("");
00055
00056 String inputLine;
00057 while ((inputLine = inputFile.readLine()) != null) {
00058 matcher.reset(inputLine);
00059 if (!matcher.lookingAt()) {
00060 outputFile.write(inputLine);
00061 outputFile.newLine();
00062 }
00063 }
00064 inputFile.close();
00065 outputFile.close();
00066 }
00067
00072 static public void main(String args[])
00073 {
00074 if (args.length>1)
00075 {
00076 final String file = args[0];
00077 final String fout = args[1];
00078 try {
00079 Grep.removeMetrics(file, fout);
00080 } catch (IOException e) {
00081
00082 e.printStackTrace();
00083 }
00084 }
00085 }
00086 }