Intro To 'ptx' Command In Linux
2023-10-11 - By Robert Elder
I use the 'ptx' command to produce the permuted index of a text document:
ptx story.txt
Once upon a time.
Once upon a time.
Once upon a time.
Once upon a time.
What Does The 'ptx' Command Do?
A permuted index, also known as a 'key word in context', is part of an obsolete method of organizing keywords in a piece of documentation.
The 'ptx' command first appeared in 1972 as a user maintained program, in the second edition of the Unix programmers manual:
This manual states that "The index for this manual was generated using ptx.":
Source: Unix Programmer's Manual, Second Edition 1972.
Example Use Case Of 'ptx' Command
Here, I have a text document in the file 'instructions.txt' that contains some instructions:
Maximum operating efficiency of a cat is achieve by petting it in slow motion.
This ptx command:
ptx instructions.txt
will produce a permuted index of all words in the document as follows:
cat is achieve by petting/ Maximum operating efficiency of a
Maximum operating efficiency of a cat is achieve by petting it in/
/efficiency of a cat is achieve by petting it in slow/
/efficiency of a cat is achieve by petting it in slow motion.
/operating efficiency of a cat is achieve by petting it in/
petting it/ Maximum operating efficiency of a cat is achieve by
a cat is achieve by petting it in slow motion. /efficiency of
/operating efficiency of a cat is achieve by petting it in slow/
of a cat is achieve by petting it in slow motion. /efficiency
achieve by petting it in slow motion. /of a cat is
Maximum operating efficiency of a cat is achieve by petting it/
achieve by petting/ Maximum operating efficiency of a cat is
/of a cat is achieve by petting it in slow motion.
cat is achieve by petting it in slow motion. /of a
Notice these words are sorted in the above output:
... .. ....... .. ........ Maximum ......... .......... .. .
....... ......... .......... .. a ... .. ....... .. ....... .. ...
........... .. . ... .. achieve .. ....... .. .. .....
........... .. . ... .. ....... by ....... .. .. .... .......
.......... .......... .. . cat .. ....... .. ....... .. ...
....... ... ....... ......... efficiency .. . ... .. ....... ..
. ... .. ....... .. ....... .. in .... ....... ........... ..
.......... .......... .. . ... is ....... .. ....... .. .. .....
.. . ... .. ....... .. ....... it .. .... ....... ...........
....... .. ....... .. .. .... motion. ... . ... ..
....... ......... .......... of . ... .. ....... .. ....... ...
....... .. ........ ....... operating .......... .. . ... ..
... . ... .. ....... .. petting .. .. .... .......
... .. ....... .. ....... .. .. slow ....... ... .
I can specify an ignore file called 'ignore.txt' to ingore common English words:
a
by
in
is
it
of
Now, if I re-run the 'ptx' command and specify the ignore file, the output will be less verbose and omit lines that center on the ignored keywords:
ptx --ignore-file=ignore.txt instructions.txt
cat is achieve by petting/ Maximum operating efficiency of a
/efficiency of a cat is achieve by petting it in slow/
/operating efficiency of a cat is achieve by petting it in/
petting it/ Maximum operating efficiency of a cat is achieve by
achieve by petting it in slow motion. /of a cat is
achieve by petting/ Maximum operating efficiency of a cat is
/of a cat is achieve by petting it in slow motion.
cat is achieve by petting it in slow motion. /of a
Creating PDF Documentation Using 'ptx' Command Output
I can use the '--format' flag to format the permuted index into a typesetting language like tex for further processing:
ptx --ignore-file=ignore.txt --format=tex instructions.txt
And the output will look something like this:
\xx {cat is achieve by petting}{}{Maximum}{ operating efficiency of a}{}
\xx {}{efficiency of a cat is}{achieve}{ by petting it in slow}{}
\xx {}{operating efficiency of a}{cat}{ is achieve by petting it in}{}
\xx {petting it}{Maximum operating}{efficiency}{ of a cat is achieve by}{}
\xx {}{achieve by petting it in slow}{motion}{.}{of a cat is}
\xx {achieve by petting}{Maximum}{operating}{ efficiency of a cat is}{}
\xx {}{of a cat is achieve by}{petting}{ it in slow motion.}{}
\xx {}{cat is achieve by petting it in}{slow}{ motion.}{of a}
I can take the above output and surround it with these latex directives to produce a finished .tex document:
cat << EOF >> indx.tex
\documentclass{article}
\usepackage{adjustbox}
\begin{document}
\newcommand{\xx}[5]{{#1} & {#2} & \textbf{{#3}} & {#4} & {#5} \\\\}
\noindent\sffamily
\begin{adjustbox}{center}
\begin{tabular}{lrllr}
& & \textbf{The Key Word} & & \\\\
\hline
EOF
ptx --ignore-file=ignore.txt --format=tex instructions.txt >> indx.tex
cat << EOF >> indx.tex
\end{tabular}
\end{adjustbox}
\end{document}
EOF
And the final '*.tex' document will look like this:
\documentclass{article}
\usepackage{adjustbox}
\begin{document}
\newcommand{\xx}[5]{{#1} & {#2} & \textbf{{#3}} & {#4} & {#5} \\}
\noindent\sffamily
\begin{adjustbox}{center}
\begin{tabular}{lrllr}
& & \textbf{The Key Word} & & \\
\hline
\xx {cat is achieve by petting}{}{Maximum}{ operating efficiency of a}{}
\xx {}{efficiency of a cat is}{achieve}{ by petting it in slow}{}
\xx {}{operating efficiency of a}{cat}{ is achieve by petting it in}{}
\xx {petting it}{Maximum operating}{efficiency}{ of a cat is achieve by}{}
\xx {}{achieve by petting it in slow}{motion}{.}{of a cat is}
\xx {achieve by petting}{Maximum}{operating}{ efficiency of a cat is}{}
\xx {}{of a cat is achieve by}{petting}{ it in slow motion.}{}
\xx {}{cat is achieve by petting it in}{slow}{ motion.}{of a}
\end{tabular}
\end{adjustbox}
\end{document}
This '*.tex' document can be compiled into a '*.dvi' file using this command:
latex indx.tex
The resulting '*.dvi' file can be compiled into a '*.ps' file using this command:
dvips indx.dvi
And finally, the resulting '*.ps' file can be compiled into a PDF document using this command:
ps2pdf indx.ps
You can view the final completed permutation index pdf document here.
And that's why the 'ptx' command is my favourite Linux command.
![]() Intro To 'stty' Command In Linux
Published 2023-10-04 |
![]() $1.00 CAD |
![]() Intro To 'nproc' Command In Linux
Published 2023-07-15 |
![]() Intro To 'comm' Command In Linux
Published 2023-09-06 |
![]() How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
![]() A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
![]() A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
![]() Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|