不精确的文字搜索


10

是否有类似grep或什至uniq除非精确搜索之外的实用程序,还是我自己编写?

我的意思是,它将查找90%(数量可能有所不同)的匹配项或类似内容。例如我有几个字符串的文件:

abc123
abd123
abc223
qwe938

在这种情况下,此类实用程序应返回前三个字符串或说它们是相似的。当然,我不知道文件内容的任何模式,例如使用grepuniq


这是特定于数据集的。例如,玛丽是玛丽还是玛丽,还是ABC是BCD?您能否举一个真实的数据示例?
AugustBitTony 2012年

Answers:


19

agrep或tre-grep会满足您的要求;它们是“近似”正则表达式匹配/ grep。有关更多信息,另请参阅Wikipedia文章

% 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'

那正是我要找的东西。谢谢。
2012年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.