Onderstaande paragrafen zijn afkomstig uit Rudyar Kipling's verhaal Brother Square-Toes1 dat dateert van 1910. Wat valt er op aan de vetgedrukte passage?

"I'll have to bide ashore and grow cabbages for a while, after I've run this cargo; but I do wish" — Dad says, going over the lugger's side with our New Year presents under his arm and young L'Estrange holding the lantern — "I just do wish that those folk which make war so easy had to run one cargo a month all this winter. It 'ud show 'em what honest work means."

"Well, I've warned ye," says Uncle Aurette. "I'll be slipping off now before your Revenue cutter comes. Give my love to Sister and take care o' the kegs. It's thicking to southward." 'I remember him waving to us and young Stephen L'Estrange blowing out the lantern. By the time we'd fished up the kegs the fog came down so thick Dad judged it risky for me to row 'em ashore, even though we could hear the ponies stamping on the beach. So he and Uncle Lot took the dinghy and left me in the smack playing on my fiddle to guide 'em back.

De passage bevat geen enkel woord dat meermaals voorkomt. Met 66 woorden is het de langste passage met die eigenschap die wiskundige Mike Keith ontdekte in een onderzoek uit 2002 van alle manuscripten op Project Gutenberg.

Vreemd genoeg komt er in hetzelfde verhaal nog een tweede uitzonderlijke passage voor — 15 opeenvolgende woorden van drie letters.

"What?" says Toby, "I thought it was Gert Schwankfelder." He put down his fiddle and took a good look at me. "Himmel!" he says. "I have hit the wrong boy. It is not the new boy. Why are you not the new boy? Why are you not Gert Schwankfelder?"

Opgave

Schrijf een bash shell script highlight dat kan gebruikt worden om een bepaalde passage uit een tekstbestand in het vet weer te geven. Het tekstbestand wordt ingelezen via standaard invoer. Aan het shell script moeten twee argumenten $$r_1\!:\!k_1$$ en $$r_2\!:\!k_2$$ doorgegeven worden, waarbij $$r_i, k_i \in \mathbb{N}_0\ (i = 1, 2)$$. De passage die in het vet moet weergegeven worden, begint bij het $$k_1$$-de karakter op de $$r_1$$-de regel en eindigt bij het $$k_2$$-de karakter op de $$r_2$$-de regel (grenzen inbegrepen). Hierbij worden zowel de posities van de regels als de posities van de karakters op een regel genummerd vanaf 1, respectievelijk van boven naar onder en van links naar rechts. Als het aantal karakters op een regel kleiner is dan $$k_1$$ dan start de passage na het laatste karakter op de regel. Als het aantal karakters op een regel kleiner is dan $$k_2$$ dan eindigt de passage bij het laatste karakter van de regel.

ANSI escape sequences

Maak gebruik van zogenaamde ANSI escape sequences2 om een passage in het vet weer te geven op de Unix commandolijn.

$ echo -e 'Dit wordt in het \033[1mVET\033[0m weergegeven!'
Dit wordt in het VET weergegeven!

Hierbij zet de escape sequence \033[1m de weergave van vette tekst aan en zet de escape sequence \033[0m de weergave van vette tekst terug uit. Let ook op het gebruik van de optie -e bij het commando echo. Deze optie zorgt ervoor dat backslashes geïnterpreteerd worden als escape-karakters.

Het shell script moet normaalgezien enkel de regels van de gegeven passage uitschrijven naar standaard uitvoer. Het script moet echter ook de volgende opties ondersteunen, waaraan telkens een natuurlijk getal $$n$$ als verplicht argument moet meegegeven worden:

Het shell script moet voor de verwerking van de opties de flexibiliteit aan de dag leggen die gebruikelijk is bij Unix commando's: volgorde van opties speelt geen rol, opties kunnen eventueel samengenomen worden, …. Het shell script moet er ook voor zorgen dat de weergave van vette tekst altijd uitstaat nadat het shell script werd uitgevoerd, ook al overlapt het aangegeven interval niet of slechts gedeeltelijk met de regels in het tekstbestand. Het shell script moet ook de volgende foutafhandeling voorzien:

Als er zich geen fouten voordoen dan moet het shell script eindigen met exit status 0.

Voorbeeld

Onderstaande voorbeeldsessie geeft aan hoe het shell script highlight moet kunnen gebruikt worden. Hierbij gaan we ervan uit dat het tekstbestand kipling.txt3 zich in de huidige directory bevindt.

$ echo "12345678901234567890" | highlight 1:5 1:12
12345678901234567890
$ echo $?
0
$ echo "12345678901234567890" | highlight 1-5 1-12
Syntax: highlight [-a <int>] [-b <int>] <int>:<int> <int>:<int>
$ echo $?
1
$ echo "12345678901234567890" | highlight 1:5
Syntax: highlight [-a <int>] [-b <int>] <int>:<int> <int>:<int>
$ echo $?
1
$ echo "12345678901234567890" | highlight -x 1:5 1:12
Syntax: highlight [-a <int>] [-b <int>] <int>:<int> <int>:<int>
$ echo $?
1
$ echo "12345678901234567890" | highlight -a 1:5 1:12
Syntax: highlight [-a <int>] [-b <int>] <int>:<int> <int>:<int>
$ echo $?
1
$ echo "12345678901234567890" | highlight 1:5 1:5
12345678901234567890
$ echo "12345678901234567890" | highlight 1:12 1:5
highlight: bad interval
$ echo $?
2
$ echo "12345678901234567890" | highlight 1:0 1:12
highlight: bad interval
$ echo $?
2
$ cat kipling.txt4 | highlight 4035:22 4036:11
the wrong boy. It is not the new boy. Why are you not the new boy? Why
are you not Gert Schwankfelder?”
$ cat kipling.txt5 | highlight -b2 4035:22 4036:11
‘“What?” says Toby, “I thought it was Gert Schwankfelder.” He put down
his fiddle and took a good look at me. “Himmel!” he says. “I have hit
the wrong boy. It is not the new boy. Why are you not the new boy? Why
are you not Gert Schwankfelder?”
$ cat kipling.txt6 | highlight -a4 4035:22 4036:11
the wrong boy. It is not the new boy. Why are you not the new boy? Why
are you not Gert Schwankfelder?”

‘“I don’t know,” I said. “The gentleman in the pink blanket brought me.”

‘Says the Indian, “He is hungry, Toby. Christians always feed the
$ cat kipling.txt7 | highlight -b2 -a4 4035:22 4036:11
‘“What?” says Toby, “I thought it was Gert Schwankfelder.” He put down
his fiddle and took a good look at me. “Himmel!” he says. “I have hit
the wrong boy. It is not the new boy. Why are you not the new boy? Why
are you not Gert Schwankfelder?”

‘“I don’t know,” I said. “The gentleman in the pink blanket brought me.”

‘Says the Indian, “He is hungry, Toby. Christians always feed the
$ cat kipling.txt8 | highlight 3886:54 3893:46
this cargo; but I do wish”--Dad says, going over the lugger’s side with
our New Year presents under his arm and young L’Estrange holding the
lantern--“I just do wish that those folk which make war so easy had to
run one cargo a month all this winter. It ‘ud show ‘em what honest work
means.”

‘“Well, I’ve warned ye,” says Uncle Aurette. “I’ll be slipping off now
before your Revenue cutter comes. Give my love to Sister and take care
$ cat kipling.txt9 | highlight -b1 -a1 3886:54 3893:46
‘“I’ll have to bide ashore and grow cabbages for a while, after I’ve run
this cargo; but I do wish”--Dad says, going over the lugger’s side with
our New Year presents under his arm and young L’Estrange holding the
lantern--“I just do wish that those folk which make war so easy had to
run one cargo a month all this winter. It ‘ud show ‘em what honest work
means.”

‘“Well, I’ve warned ye,” says Uncle Aurette. “I’ll be slipping off now
before your Revenue cutter comes. Give my love to Sister and take care
o’ the kegs. It’s thicking to southward.” ‘I remember him waving to us

Bronnen