Skip to content

Instantly share code, notes, and snippets.

@jyn514
Created March 18, 2023 07:06
Show Gist options
  • Save jyn514/c2cebf689751d23c7b170021683b94d1 to your computer and use it in GitHub Desktop.
Save jyn514/c2cebf689751d23c7b170021683b94d1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import re
import sys
def sizeof_fmt(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return f"{num:3.1f}{unit}{suffix}"
num /= 1024.0
return f"{num:.1f}Yi{suffix}"
for line in sys.stdin:
columns = line.split()
if len(columns) > 5 and re.fullmatch("[0-9a-fA-F]+", columns[5]):
columns[5] = sizeof_fmt(int(columns[5], base=16))
print(" ".join(columns))
else:
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment