@Joseph R.'s accepted answer with the history is good, but let's look at how it might be used.
ptx
generates a permuted term index ("ptx") from text. An example is easiest to understand:
$ cat input
a
b
c
$ ptx -A -w 25 input
:1: a b c
:2: a b c
:3: a b c
^^^^ ^ ^^^^-words to the input's right
| +-here is the actual input
+-words to the input's left
Down the right you see the different words from the input and the left and right word context surrounding them. The first word is "a". It occurs on line one and is followed by "b" and "c" to its right. The second word is "b", which occurs on line two with "a" to its left and "c" to its right. Finally, "c" occurs on line three and is proceeded by "a" and "b".
Using this, you can find the line number and surrounding words to any word in a text. This sounds a lot like grep
, eh? The difference is that ptx
understands the structure of text, in logical units of words and sentences. This makes the contextual output of ptx
more relevant when dealing with English text than grep.
Let's compare ptx
and grep
, using the first paragraph of James Ellroy's American Tabloid:
$ cat text
America was never innocent. We popped our cherry on the boat over and looked back with no regrets. You can’t ascribe our fall from grace to any single event or set of circumstances. You can’t lose what you lacked at conception.
Here's grep
(with color matches manually changed to be surrounded by //
):
$ grep -ni you text
1:America was never innocent. We popped our cherry on the boat over and looked back with no regrets. /You/ can’t ascribe our fall from grace to any single event or set of circumstances. /You/ can’t lose what /you/ lacked at conception.
Here's ptx
:
$ ptx -Afo <(echo you) text
text:1: /back with no regrets. You can’t ascribe our fall/
text:1: /or set of circumstances. You can’t lose what you/
text:1: /. You can’t lose what you lacked at conception.
Because grep
is line-oriented, and this paragraph is all one line, the grep
output isn't quite as concise or helpful as the output from ptx
.