Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. for line in intersect:
  2. cmd=""" grep "CHECKOUT_REVISION" |cut -d'"' -f2"""%fst_directory
  3. cmd_test=os.system(cmd)
  4.  
  5. this is a test
  6.  
  7.  
  8. another line
  9.  
  10. CHECKOUT_REVISION this must be stored
  11.  
  12. some other things
  13. CHECKOUT_REVISION another line to store
  14.  
  15. #!/usr/bin/env python
  16.  
  17. # path to the file to read from
  18. my_file = "/home/eday/test.txt"
  19. # what to look in each line
  20. look_for = "CHECKOUT_REVISION"
  21. # variable to store lines containing CHECKOUT_REVISION
  22. temp = []
  23.  
  24. with open(my_file, "r") as file_to_read:
  25. for line in file_to_read:
  26. if look_for in line:
  27. temp.append(line)
  28.  
  29. # print the contents of temp variable
  30. print (temp)
  31.  
  32. $ ['CHECKOUT_REVISION this must be stored', 'CHECKOUT_REVISION another line to store']
  33.  
  34. result = []
  35. for line in open('filename'):
  36. if 'CHECKOUT_REVISION' in line:
  37. result.append(line.split(''"'')[1])
  38.  
  39. some lines
  40. CHECKOUT_REVISION="revision one"
  41. some other lines
  42. CHECKOUT_REVISION="revision two"
  43. other lines
  44.  
  45. revision one
  46. revision two
  47.  
  48. #!/usr/bin/env python
  49.  
  50. import sys
  51.  
  52. pattern = sys.argv[1]
  53. fileName = sys.argv[2]
  54.  
  55. # variable to store lines containing CHECKOUT_REVISION
  56. count=0
  57. temp = []
  58.  
  59. with open(fileName, "r") as file_to_read:
  60. for line in file_to_read:
  61. if pattern in line:
  62. #IN case you want to have number of hits
  63. count=count+1
  64. temp.append(line)
  65.  
  66. # print the contents of temp variable
  67.  
  68. for i in range(count):
  69. print (temp[i].rstrip())
  70.  
  71. python "pattern" thisScript.py
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement