Skip to content

Instantly share code, notes, and snippets.

@ishideo
Last active April 16, 2026 13:57
Show Gist options
  • Select an option

  • Save ishideo/52fe1a57282bf2e369cdab8e9850d8a1 to your computer and use it in GitHub Desktop.

Select an option

Save ishideo/52fe1a57282bf2e369cdab8e9850d8a1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
bb -e '
(let [ips (str/split-lines (slurp "ip.tsv"))
table (map #(str/split % #"\t") (str/split-lines (slurp "ip_domain.tsv")))
idx (into {} (map (juxt first second) table))]
(doseq [ip ips]
(println (get idx ip))))'
#!/usr/bin/env bash
parallel -j1 'bb -e "
(let [ip \"{}\"]
(->> (slurp \"ip_domain.tsv\")
str/split-lines
(map #(str/split % #\"\\t\"))
(filter #(= ip (first %)))
(map #(nth % 1))
(run! println)))"' :::: ip.tsv
#!/usr/bin/env bash
cat ip_domain.tsv | bb -e '
(->> (slurp *in*)
str/split-lines
(map #(str/split % #"\t"))
(into {} (map (juxt first second)))
prn)' \
| bb -e '
(let [idx (edn/read-string (slurp *in*))]
(doseq [ip (str/split-lines (slurp "ip.tsv"))]
(println (get idx ip))))'
@ishideo
Copy link
Copy Markdown
Author

ishideo commented Apr 10, 2026

#!/usr/bin/env bash

bb -e '
(let [idx (->> (slurp "ip_domain.tsv")
               str/split-lines
               (map #(str/split % #"\t"))
               (into {} (map (juxt first second))))]
  (doseq [ip (str/split-lines (slurp "ip.tsv"))]
    (println (get idx ip))))'

@ishideo
Copy link
Copy Markdown
Author

ishideo commented Apr 10, 2026

#!/usr/bin/env bash

bb -e '
  (->> (slurp "ip_domain")
       str/split-lines
       (map #(str/split % #"\t"))
       (into {} (map (juxt first #(nth % 1))))
       prn)' \
| bb -e '
  (let [idx (edn/read-string (slurp *in*))]
    (doseq [ip (str/split-lines (slurp "ip.tsv"))]
      (println (get idx ip))))'

@ishideo
Copy link
Copy Markdown
Author

ishideo commented Apr 10, 2026

#!/usr/bin/env bash

clojure -M -e '
  (->> (slurp "ip_domain.tsv")
       clojure.string/split-lines
       (map #(clojure.string/split % #"\t"))
       (into {} (map (juxt first #(nth % 1))))
       prn)' \
| clojure -M -e '
  (let [idx (clojure.edn/read-string (slurp *in*))]
    (doseq [ip (clojure.string/split-lines (slurp "ip.tsv"))]
      (println (get idx ip))))'

@ishideo
Copy link
Copy Markdown
Author

ishideo commented Apr 16, 2026

#!/usr/bin/env python

import sys

def read_lines(filepath: str) -> list[str]:
    with open(filepath) as f:
        return f.read().splitlines()

def build_index(table_path: str) -> dict[str, str]:
    lines = read_lines(table_path)
    return dict(
        row[0], row[1]
        for line in lines
        if len(row := line.split("\t")) >= 2
    )

def lookup(ips: list[str], index: dict[str, str]) -> list[str]:
    return [index.get(ip, "") for ip in ips]

def main():
    ips = read_lines("ip.tsv")
    index = build_index("ip_domain.tsv")
    results = lookup(ips, index)
    print("\n".join(results))

if __name__ == "__main__":
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment