Created
March 18, 2023 07:06
-
-
Save jyn514/c2cebf689751d23c7b170021683b94d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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