DIVERT(1)
π NAME π
Divert β the Text Diversion Filter β¨
okay bestie, real talk: this is the DIVERT(1) page from the EN Tools manual set, and it's genuinely one of the most underrated little text filters out there. no cap. π
β¨ SYNOPSIS β¨
divert [-o outputfile] [-q] [-v] [inputfile]
π¦ DESCRIPTION π¦
So divert reads inputfile β or stdin if you don't hand it a file β and runs a 2-pass diversion filter over whatever's in there. Pass 1 gathers up all the diversion locations, and pass 2 recursively expands those locations at their dump positions. πΈ
And like⦠how does it know what to do? The whole filter is steered by directives you drop straight into the input data:
{#NAME#}(or<<NAME>>) β this defines the dump position of the locationNAME. All the accumulated data that finally has to be diverted toNAMEgets inserted right at this data position. Notice: the final data of a locationNAMEdoesn't have to be known at this point, because expanding those location dumps happens in pass 2. π You can dump a location more than once too, but the contents is always the same, no matter what data position the location dump tag sits at.NAMEcan be any symbolic name matching[a-zA-Z][a-zA-Z0-9_]*.{#[!]NAME[!]#:(or..[!]NAME[!]>>) β this enters the locationNAME, i.e. it diverts the data flow to it (hence the name of this filter, iykyk). In other words: the data flow now goes on at locationNAME, and all following data β up to end of file or the next location leave tag β gets appended to locationNAME. π You can nest diversions by entering other locations at any point, because the locations are remembered on a stack. The default entered location is named"main". The top most location is named"null", which neither can be entered nor leaved explicitly. But of course the"null"diversion can be manually dumped, for instance when you're using it for error messages.
There are two special features for diverting data, and they're controlled by the ! characters preceding or following the NAME identifier:
!NAMEβ sets the data flow position to the begin of locationNAME, i.e. it actually discards the current (already diverted) contents of locationNAMEbefore entering it. Use this to overwrite a location's contents. π₯NAME!β marks this location entry as overwritable, i.e. it enters locationNAME, but when the corresponding leave tag is found, the data-flow position forNAMEgets automatically reset to its begin. Use this if you want to set the default contents for a location that only gets used if no other diversions occur to it (because any following diversions to this location will overwrite the contents). This feature is usually used for a template scheme. β¨!NAME!β just the combination of the above two features. Use this to both discard the current contents of locationNAMEand set a new default for it.
:#[NAME]#}(or<<[NAME]..) β this leaves the current location, i.e. it enters again the location that was active when this location was entered. There's no need to leave all locations at the end of the input data β all still-entered locations are automatically left at end of file, because that's essential for a template scheme. π«Ά
Notice that there are two ways of using (and thinking) about the filtering mechanism this program provides:
π Macro Mechanism
This is the "predefined" way of thinking here. Use it like this:
FOO
{#BAR#}
QUUX
{#BAR#:
BAZ
:##}
Here you're thinking of the mechanism as a macro mechanism, where you expand a macro at one data position while you define it via begin and end tags. π
π¦ Diversion Mechanism
This is the alternative way of thinking. Use it like this:
FOO
<<BAR>>
QUUX
..BAR>>
BAZ
<<..
In other words: you're thinking of the mechanism as a diversion mechanism, where you dump a location at one data position while you divert to it by entering and leaving the location (here BAR) at other positions. π
You can even intermix both ways, because both are just alternative syntax variants that are treated the same. no cap, fr fr.
πΈ EXAMPLE πΈ
{#HEAD#}
{#BODY#}
{#FOOT#}
{#FOOT#:
Quux
:##}
{#BODY#:
Bar
:##}
{#HEAD#:
Foo
:##}
π OPTIONS π
-o outputfileβ redirects the output to outputfile. Usually the output gets sent tostdoutif no such option is specified, or if outputfile is"-". π€-qβ sets quiet mode, where warnings are suppressed. π€«-vβ sets verbose mode, where some processing information will be given onstderr. π
π AUTHORS π
- Ralf S. Engelschall β
rse@engelschall.comβwww.engelschall.com - Denis Barbier β
barbier@engelschall.com
and that's the whole page, bestie!! this one's from EN Tools, dated 2020-11-29, and it's the DIVERT(1) entry of your manual set β go forth and divert, you absolute icon. πβ¨ππ¦
π¦ where this page comes from
- debian bookworm: wml 2.32.0~ds1-1 Β· GPL-2.0-or-later
- debian trixie: wml 2.32.0~ds1-1 Β· GPL-2.0-or-later
- ubuntu jammy: wml 2.32.0~ds1-1 Β· GPL-2.0-or-later
- ubuntu noble: wml 2.32.0~ds1-1 Β· GPL-2.0-or-later
- ubuntu questing: wml 2.32.0~ds1-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms