SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pyperclip
  2. import re
  3.  
  4. #This Regex looks for a whole line, which is followed by a line with one of the fields in the second column.
  5. serviceRegex = re.compile(r'(^.*$)(?:=?\r|\n)(.*?(?:Healthy|Unhealthy|Degraded|Unknown).*)',re.MULTILINE)
  6. serviceTable=pyperclip.paste()
  7.  
  8. #debug print
  9. #print(serviceRegex.findall(serviceTable))
  10.  
  11. #initializing the variable before the loop
  12. returnPaste=''
  13.  
  14. #Iterate through the returns from the Regex, grabbing only Group 1 (the actual result), and then build a string of multiple lines from it.
  15. for x in serviceRegex.finditer(serviceTable):
  16.     print(x.group(1))
  17.     returnPaste += x.group(1)+'\n'
  18.  
  19. #return the result to the clipboard
  20. pyperclip.copy(returnPaste)
  21.  
  22.  
  23.  
  24. |-----------------------CODE BLOCK ENDS-------------------------|
  25.  
  26. Example input data:
  27.  
  28. Service Name Goes here!
  29. Unknown
  30. 07/21/2019 17:17 PDT
  31. Some Dude's Name (XXXXYYYZZZ)
  32. v-thisisanalias@acompany.com
  33. I am Also a Service!
  34. Healthy
  35. 07/21/2019 17:17 PDT
  36. Some Dude's Name (XXXXYYYZZZ)
  37. 07/21/2019 17:54 PDT
  38. v-thisisanalias@anothercompany.com
  39. Am I a service?
  40. Degraded
  41. 07/21/2019 17:17 PDT
  42. fields!
  43. testingextrafields!
  44. Some Dude's Name (XXXXYYYZZZ)
  45. 07/21/2019 17:54 PDT
  46. v-thisisanalias@whoknows.com
  47.  
  48.  
  49. Example output data:
  50.  
  51. Service Name Goes here!
  52. I am Also a Service!
  53. Am I a service?
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top