 <p>I know my approach might be not cute at all but it works. Would be one solution:</p> <pre><code>String filePath = "res/textfile.txt"; String line; List&lt;String&gt; myL = new ArrayList&lt;String&gt;(); try { BufferedReader read = new BufferedReader(new FileReader(filePath)); while((line = read.readLine()) != null) { if(line.contains("Resumed Activity") || line.contains("Starting: Intent")) { String str[] = line.split(" "); for(String s : str) { if(s.contains("com.amazon")) myL.add(s); } } } for(String s : myL) { System.out.println(s); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p><strong>UPDATED:</strong> I just read through your post again and updated my solution. I missed somehow that lines including "Resumed Activity" or "Starting: Intent" should be removed.</p>