0

I want to find the following pattern in a file like

subclass "Pool1" 11:22:33:44:55:66    {

      dynamic;

}

the above pattern I have to find in a file.

How can I find either using java or Unix command?

Raptor
  • 53,206
  • 45
  • 230
  • 366
Saxena Shekhar
  • 219
  • 6
  • 22

1 Answers1

1

You can find like this.

    File file = new File("data/pattern.txt");
    Pattern pat = Pattern.compile("subclass \"Pool1\" 11:22:33:44:55:66 \\{\\s*dynamic;\\s*\\}");
    String content = Files.lines(file.toPath()).collect(Collectors.joining("\n"));
    Matcher m = pat.matcher(content);
    while (m.find()) {
        System.out.printf("found at %d-%d%n", m.start(), m.end());
    }