Script to find subpatterns in a file