fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate: run in temp dir
  4. t=$(mktemp -d -t ideone.XXXXXXXX) || exit
  5. trap 'rm -rf "$t"' ERR EXIT
  6. cd "$t"
  7.  
  8. cat <<\: >total.txt
  9. ============
  10. | hafuia
  11. | 0xb34a47885262f9d8673dc77de7b583961134f09fb03620b29d282c32ee6932be
  12. | 0xD0b2612a6eE3111114b43b25322C6F08A251D38D
  13. | Total: 47.62874464666479$
  14. |
  15. |
  16. | Tokens eth:
  17. | 20.608732$ MANA
  18. |
  19. | Protocols cro:
  20. | 17.840052$ VVS Finance
  21. | 8.953779$ V3S Finance
  22. ============
  23. | asdf
  24. | 0x72e164aa187feaff7cb28a74b7ff800a0dfe916594c70f141069669e9df5a23b
  25. | 0xC7dFe558ed09F0f3b72eBb0A04e9d4e99af0bd0D
  26. | Total: 22.908481672796988$
  27. |
  28. |
  29. | Tokens eth:
  30. | 22.376087$ SOS
  31. ============
  32. | asdf
  33. | 0xbce666bca3c862a2ee44651374f95aca677de16b4922c6d5e7d922cc0ac42a3d
  34. | 0x5870923a244f52fF2D119fbf5525421E32EC006e
  35. | Total: 9.077030269778557$
  36. |
  37. |
  38. | Tokens eth:
  39. | 8.942218$ SOS
  40. ============
  41. :
  42.  
  43. cat <<\: >prog.py
  44. def items(file):
  45. """
  46. Generator to yield items from filename
  47. whose "Tokens eth:" is above 20.0
  48. """
  49. with open(file) as lines:
  50. item = []
  51. tokens = 0
  52. capture = False
  53. for line in lines:
  54. if line == "============\n":
  55. if tokens > 20.0:
  56. yield tokens, item
  57. item = []
  58. tokens = 0
  59. continue
  60. if capture:
  61. tokens = float(line.strip().split()[-2].rstrip("$"))
  62. capture = False
  63. if line.startswith("| Tokens eth:"):
  64. # Set flag to capture next line when we get to it
  65. capture = True
  66. item.append(line)
  67.  
  68. def main():
  69. import sys
  70. print("============")
  71. for tokens, item in sorted(list(items(sys.argv[1]))):
  72. print("".join(item), end="")
  73. print("============")
  74.  
  75. if __name__ == "__main__":
  76. main()
  77. :
  78.  
  79. python3 prog.py total.txt
Success #stdin #stdout 0.04s 9208KB
stdin
Standard input is empty
stdout
============
| hafuia
| 0xb34a47885262f9d8673dc77de7b583961134f09fb03620b29d282c32ee6932be
| 0xD0b2612a6eE3111114b43b25322C6F08A251D38D
| Total: 47.62874464666479$
|
|
| Tokens eth:
| 20.608732$ MANA
|
| Protocols cro:
| 17.840052$ VVS Finance
| 8.953779$ V3S Finance
============
| asdf
| 0x72e164aa187feaff7cb28a74b7ff800a0dfe916594c70f141069669e9df5a23b
| 0xC7dFe558ed09F0f3b72eBb0A04e9d4e99af0bd0D
| Total: 22.908481672796988$
|
|
| Tokens eth:
| 22.376087$ SOS
============