Skip to content

Instantly share code, notes, and snippets.

@sqd
Created November 11, 2020 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sqd/9bc7257c47016d679c9294ca8f06b4f7 to your computer and use it in GitHub Desktop.
Save sqd/9bc7257c47016d679c9294ca8f06b4f7 to your computer and use it in GitHub Desktop.
normalize pager output
#!/usr/bin/python
import sys
import re
input_str = sys.stdin.read()
shell_pid = re.compile(r'vm_create\t\((\d+)').search(input_str).group(1)
shell_pid = shell_pid
pid_list = [shell_pid]
for match in re.finditer(r'vm_create\t\((\d+), (\d+)\)', input_str):
pid_list.append(match.group(2))
sub = 0
input_str = input_str.replace(f'({pid_list[0]}, {pid_list[1]})', '(0, 1)')
for pid in pid_list:
input_str = input_str.replace(f'({pid}', f'({sub}')
input_str = input_str.replace(f'{pid})', f'{sub})')
sub += 1
sys.stdout.write(input_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment