неточний пошук тексту


10

Чи є якась утиліта на кшталт grepабо навіть, uniqале для неточного пошуку, або я повинен сам це написати?

Я маю на увазі, що це буде 90% (кількість може відрізнятися), або щось подібне. Наприклад, у мене є файл з декількома рядками:

abc123
abd123
abc223
qwe938

У цьому випадку така утиліта повинна повернути перші три рядки або сказати, що вони схожі. Звичайно, я не знаю жодного шаблону вмісту файлу, як у випадку з grepабо uniq.


Це дуже специфічний набір даних. Наприклад, Марія схожа на Марі, чи ABC схожа на BCD? Чи можете ви навести приклад своїх даних у реальному світі?
EightBitTony

Відповіді:


19

agrep або tre-grep зробить те, що ви просите; вони "приблизне" відповідність регулярного вираження / grep. Для отримання додаткової інформації дивіться також статтю у Вікіпедії .

% tre-agrep --help | head             (05-23 16:53)
Usage: tre-agrep [OPTION]... PATTERN [FILE]...
Searches for approximate matches of PATTERN in each FILE or standard input.
Example: `tre-agrep -2 optimize foo.txt' outputs all lines in file `foo.txt'     that
match "optimize" within two errors.  E.g. lines which contain "optimise",
"optmise", and "opitmize" all match.

Regexp selection and interpretation:
  -e, --regexp=PATTERN      use PATTERN as a regular expression
  -i, --ignore-case         ignore case distinctions
  -k, --literal             PATTERN is a literal string


% agrep  | head                       (05-23 16:53)
usage: agrep [-@#abcdehiklnoprstvwxyBDGIMSV] [-f patternfile] [-H dir] pattern [files]

summary of frequently used options:
(For a more detailed listing see 'man agrep'.)
-#: find matches with at most # errors
-c: output the number of matched records
-d: define record delimiter
-h: do not output file names
-i: case-insensitive search, e.g., 'a' = 'A'
-l: output the names of files that contain a match
-n: output record prefixed by record number
-v: output those records that have no matches
-w: pattern has to match as a word, e.g., 'win' will not match 'wind'
-B: best match mode. find the closest matches to the pattern
-G: output the files that contain a match
-H 'dir': the cast-dictionary is located in directory 'dir'

Це саме те, що я шукаю. Дякую.
пік
Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.