Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there any utility like grep or even uniq but for inexact search or I should write it myself?

I mean it will look at 90% (number may vary) matching, or smth like that. For example I have file with several strings:

abc123
abd123
abc223
qwe938

In this case such utility should return the first three string or say they are similar. Of course I don't know any pattern of file's content like in case with grep or uniq.

share|improve this question
    
This is very data set specific. For example, is Mary like Marie, or is ABC like BCD? Can you give a real world example of your data? –  EightBitTony May 23 '12 at 21:52

1 Answer 1

up vote 14 down vote accepted

agrep or tre-grep will do what you're asking; they're "approximate" regex matching/grep. For more information, also see the Wikipedia article.

% 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'
share|improve this answer
    
That's exactly the thing I'm looking for. Thank you. –  rush May 23 '12 at 22:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.