LINUX.ORG.RU

История изменений

Исправление Nervous, (текущая версия) :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс. Итааааак… всего три шага к успеху!

  1. Сохранить кот в файлик, chmod a+x файлик
  2. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  3. Запустить: ./файлик текстовый-файлик символы [символы ...]

Пример:

$ ./find-words 
Find words in text files that contain given char sequence(s).
Usage: find-words <text-file> <char-sequence> [char-sequence ...]

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words that contain given char sequence(s) in text files.\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs))
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс. Итааааак… всего три шага к успеху!

  1. Сохранить кот в файлик, chmod a+x файлик
  2. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  3. Запустить: ./файлик текстовый-файлик символы [символы ...]

Пример:

$ ./find-words 
Find words in text files that contain given char sequence(s).
Usage: find-words <text-file> <char-sequence> [char-sequence ...]

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs))
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс. Итааааак… всего три шага к успеху!

  1. Сохранить кот в файлик, chmod a+x файлик
  2. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  3. Запустить: ./файлик текстовый-файлик символы [символы ...]

Пример:

$ ./find-words 
Find words in text files that contain given char sequence(s).
Usage: find-words <text-file> <char-sequence> [char-sequence]

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs))
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс. Итааааак… всего три шага к успеху!

  1. Сохранить кот в файлик, chmod a+x файлик
  2. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  3. Запустить: ./файлик текстовый-файлик символы [символы ...])

Пример:

$ ./find-words 
Find words in text files that contain given char sequence(s).
Usage: find-words <text-file> <char-sequence> [char-sequence]

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs))
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс. Итааааак… всего три шага к успеху!

  1. Сохранить кот в файлик, chmod a+x файлик
  2. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  3. Запустить: ./файлик текстовый-файлик символы [символы ...])

Пример:

$ ./find-words 
Find words in text files that contain given char sequence(s).
Usage: find-words <text-file> <char-sequence> [char-sequence]

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs) )
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс. Итааааак… всего три шага к успеху!

  1. Сохранить кот в файлик, chmod a+x файлик
  2. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  3. Запустить: ./файлик текстовый-файлик символы [символы ...])

Пример:

$ ./find-words 
Find words in text files that contain given char sequence(s).
Usage: find-words <text-file> <char-sequence> [char-sequence]

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs) )
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс. Итааааак… всего три шага к успеху!

  1. Сохранить кот в файлик, chmod a+x файлик
  2. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  3. Запустить: ./файлик текстовый-файлик символы [символы ...])

Пример:

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs) )
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс.

  1. Сохранить кот в файлик
  2. chmod a+x файлик
  3. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  4. Запустить: ./файлик текстовый-файлик символы [символы ...])

Пример:

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs) )
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс.

  1. Сохранить кот в файлик
  2. chmod a+x файлик
  3. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  4. Запустить: ./файлик текстовый-файлик символы [символы ...])

Пример:

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (try
      (->> text-file
           (find-words (map successive-chars-regex char-seqs) )
           (map println)
           doall)
      (catch Exception e (println (.getMessage e))))))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс.

  1. Сохранить кот в файлик
  2. chmod a+x файлик
  3. Скачать бабашку — самодостаточный бинарник, положить её в $PATH
  4. Запустить: ./файлик текстовый-файлик символы [символы ...])

Пример:

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (fs/file-name *file*)
             "<text-file> <char-sequence> [char-sequence]")
    (->> text-file
         (find-words (map successive-chars-regex char-seqs))
         (map println)
         doall)))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс.

  1. Сохранить кот в файлик
  2. chmod a+x файлик
  3. Скачать бабашку — самодостаточный бинарник, положить её в PATH 4../файлик текстовый-файлик символы [символы …]`)

Пример:

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (fs/file-name *file*)
             "<text-file> <char-sequence> [char-sequence]")
    (->> text-file
         (find-words (map successive-chars-regex char-seqs))
         (map println)
         doall)))

Исправление Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс.

  1. Сохранить кот в файлик
  2. chmod a+x файлик
  3. Скачать бабашку — самодостаточный бинарник, положить её в $PATH 4../файлик текстовый файлик символы [символы ...])

Пример:

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (fs/file-name *file*)
             "<text-file> <char-sequence> [char-sequence]")
    (->> text-file
         (find-words (map successive-chars-regex char-seqs))
         (map println)
         doall)))

Исходная версия Nervous, :

Ну ладно, так и быть — одним куском. Только сегодня, зато совершенно бесплатно и без смс.

  1. Сохранить кот в файлик
  2. chmod a+x файлик
  3. Скачать бабашку — самодостаточный бинарник, положить её в $PATH 4../файлик текстовый файлик символы [символы ...])

Пример:

$ ./find-words /tmp/Звёздная\ пехота.txt аеиоу аеуюя
знаменитому
экзаменующийся
#!/usr/bin/env bb

;; -*- mode: clojure -*-

(ns find-words
  (:require
   [babashka.fs :as fs]
   [clojure.java.io :as io]
   [clojure.string :as s]))

(defn successive-chars-regex
  "Returns a regex that matches a string containing given (unicode) chars in order."
  [chars]
  (let [unicode-escaped-chars    (map #(format "\\u%04x" (int %)) chars)
        exclude-chars-subpattern (format "[^%s]*" (s/join unicode-escaped-chars))]
    (->> unicode-escaped-chars
         (reduce (fn [acc val]
                   (str acc val exclude-chars-subpattern)) exclude-chars-subpattern)
         re-pattern)))

(defn re-some-matches
  "Returns true if any of `regexes` matches `string`."
  [regexes string]
  (boolean (some #(re-matches % string) regexes)))

(defn file-word-seq
  "Returns a sequence of words in `file`, matched by `word-regex`."
  [file word-regex]
  (->> (line-seq (io/reader file))
       (keep #(re-seq word-regex %))
       flatten))

(defn find-words
  "Returns a sequence of words in `file` that match at least one of
  `regexes`."
  ([regexes file]
   (find-words regexes file #"[\p{L}\p{N}]+"))
  ([regexes file word-regex]
   (->> (file-word-seq file word-regex)
        (filter #(re-some-matches regexes %)))))


(let [[text-file & char-seqs] *command-line-args*]
  (if (or (not text-file)
          (empty? char-seqs))
    (println "Find words in text files that contain given char sequence(s).\nUsage:"
             (str "./" (fs/file-name *file*))
             "<text-file> <char-sequence> [char-sequence]")
    (->> text-file
         (find-words (map successive-chars-regex char-seqs) )
         (map println)
         doall)))