Skip to content

Instantly share code, notes, and snippets.

@mdeous
Created June 13, 2014 20:21
Show Gist options
  • Save mdeous/d3269b66d5d1cba526dc to your computer and use it in GitHub Desktop.
Save mdeous/d3269b66d5d1cba526dc to your computer and use it in GitHub Desktop.
In [23]: def find_offsets(filename, regex):
...: with open(filename) as ifile:
...: lineno = 1
...: for line in ifile:
...: for result in regex.finditer(line):
...: print "Result found line %d column %d" % (lineno, result.start())
...: lineno += 1
...:
In [24]: r = re.compile('=')
In [25]: find_offsets('/home/mdeous/.bashrc', r)
Result found line 15 column 41
Result found line 18 column 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment