Here is a similar program I needed to write for work:
public class LogReader {
public static void main(String[] args) throws IOException
{
mapper("workId=\"1915900093138425722");
}
public static void mapper(String id) throws IOException
{
String sepText = "";
FileWriter fileWriter;
BufferedReader br = new BufferedReader(new FileReader(new File("Work.txt")));
String line = "";
while ((line = br.readLine()) != null)
{
System.out.print(line);
sepText += line.substring(0, 23) + "\n";
int startAttIdMarker = line.indexOf(id);
int midAttIdMarker = line.indexOf('"', startAttIdMarker + 1);
int endAttIdMarker = line.indexOf('"', midAttIdMarker + 1 );
sepText += "attributeSetId = " + line.substring(midAttIdMarker + 1 , endAttIdMarker) + "\n" + "\n";
sepText += "********************************************" + "\n";
}
br.close();
File newTextFile = new File("worker.txt");
fileWriter = new FileWriter(newTextFile);
fileWriter.write(sepText);
fileWriter.close();
}
}
You feed a string to the function mapper and it searches for all lines with that string. It then writes those lines to a string which is in turn written to a file of it's own.
Best thing to do is play around with some sample code like this and see what happens.