Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2010 Doug Hellmann. All rights reserved.
  5. #
  6. """Simplistic grep implementation
  7. """
  8. #end_pymotw_header
  9.  
  10. import fileinput
  11. import glob
  12. import sys
  13.  
  14. from_base = sys.argv[1]
  15. to_base = sys.argv[2]
  16. files = sys.argv[3:]
  17.  
  18. for line in fileinput.input(files, inplace=True):
  19. if fileinput.isfirstline():
  20. sys.stderr.write('Started processing %s\n' %
  21. fileinput.filename())
  22. sys.stderr.write('Directory contains: %s\n' %
  23. glob.glob('etc_hosts.txt*'))
  24. line = line.rstrip().replace(from_base, to_base)
  25. print line
  26.  
  27. sys.stderr.write('Finished processing\n')
  28. sys.stderr.write('Directory contains: %s\n' %
  29. glob.glob('etc_hosts.txt*'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement