upvote
> awk wasn't very portable because you still had the awk,nawk,gawk flavors

Debian and Ubuntu both ship with mawk and Alpine has the busybox flavor of awk (nawk like). MacOS still ships with a default nawk. I don't know the scene has changed much, still many flavors out there.

reply
The issues from the 80s/90s were mostly fixed by POSIX in the 2000's. IIRC all major Unix-like systems ship with awk implementations that are POSIX-compliant by default today.

With a few warts of course, but not like back then.

reply
Perl was in 1997 and is today a better awk+sed.
reply
Better is to use the typesetting language

Even on MacOS, save this as `doc.tr`

     .\" Index Macro
     .de IX
     .tm \\$1^\\$2^\\n%
     ..
     .\" Content
     .sp 2
     This is the first page.
     We are talking about the history of Unix.
     .IX "Operating Systems" "Unix"
     .bp
     This is the second page.
     Here we discuss the C language.
     .IX "Languages" "C"
     .bp
     This is the third page.
     We go back to talking about Unix.
     .IX "Operating Systems" "Unix"
The index will be output on stderr with:

     % groff doc.tr > output.ps 2> raw.idx

Which will output the following that you could use bash/sed/awk/perl/... to make into another troff file.

     % sort -t '^' -k2,2 -k1,1 raw.idx                    
     Languages^C^2
     Operating Systems^Unix^1
     Operating Systems^Unix^3
(Note: `^` as a delimiter is an old Unix thing, just going really retro)

Even inserting the `.IX ...` lines on a string match in the troff file is fairly easy. But somehow they were parsing the typeset output, not sure what kind. But no need to try and track page numbers when typesetting languages do that for you.

TL;DR What I was saying is if you are using a typesetting language, use the tools in the typesetting language when possible. If you can do it in troff you can do it in LaTeX with makeindex etc...

reply