Created
April 14, 2026 11:26
-
-
Save ishideo/7d3c4890b6814537b5077b5ec3ffad3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 bash | |
| cat ip_domain.tsv | bb -e ' | |
| (->> (line-seq (java.io.BufferedReader. *in*)) | |
| (map #(str/split % #"\t")) | |
| (group-by first) | |
| (map (fn [[ip rows]] (str ip "\t" (str/join ";" (map second rows))))) | |
| (run! println)) | |
| ' > ip_domains.tsv |
Author
#!/usr/bin/env python
import sys
from collections import defaultdict
def parse_line(line: str) -> tuple[str, str] | None:
parts = line.rstrip("\n").split("\t")
if len(parts) < 2 or not parts[0]:
return None
return parts[0], parts[1]
def group_by_ip(lines: list[str]) -> dict[str, list[str]]:
groups = defaultdict(list)
for line in lines:
parsed = parse_line(line)
if parsed:
ip, domain = parsed
groups[ip].append(domain)
return groups
def format_output(groups: dict[str, list[str]]) -> list[str]:
return [f"{ip}\t{';'.join(domains)}" for ip, domains in groups.items()]
def main():
lines = sys.stdin
groups = group_by_ip(lines)
output = format_output(groups)
print("\n".join(output))
if __name__ == "__main__":
main()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.