SLICE(1)
okay bestie, sit down, hydrate, and let me tell you about slice(1) from the EN Tools era β she's a text-slicing queen and she's about to change your whole ASCII workflow π
β¨ NAME β¨
Slice β Extract pre-defined slices from an ASCII file. periodt.
β¨ SYNOPSIS β¨
slice [-v] [-y outputpolicy] [-o
sliceterm:outputfile[@chmodcmd][#outputpolicy] ..] [inputfile]
slice [-V] [-h]
β¨ VERSION β¨
@SLICE_VERSION@
like, that's literally her whole version string, no cap π
β¨ DESCRIPTION β¨
πΈ Input Principle πΈ
So here's the vibe: slice reads inputfile (or straight from STDIN if you didn't hand her an inputfile or if you passed "-") and chops up its already-prepared ASCII contents into possibly overlapping areas called slices. Obsessed.
These slices get determined by enclosing blocks, defined by begin and end delimiters that have to already be in the file (she's not out here inventing structure for you, bestie). Those block delimiters use the syntax
[NAME: ... :NAME]
or alternatively (and this only works if there's no misinterpretation possible, i.e. no overlapping or stacked slices)
[NAME: ... :]
The NAME identifier has to match against the regular expression `"[_A-Z0-9]+"`, which means NAME is a string made up of only uppercase letters, digits, or underscore characters. simple as that π
You can have as many of these slice definitions as you want, and you can have more than one slice with the same name. The resulting slice is the union of all equally-named slices. And actually, use that! It's how you spread one big slice across disjunct pieces of your inputfile. iconic behavior fr fr.
π¦ Output Selection Scheme π¦
The final output data gets calculated by a slice term consisting of slice names and set theory operators. The following syntax is recognized (in order of LR(1) grammar parsing) for slice terms:
SLICE_TERM ::= "NAME"β The sliceNAMEitself. This name has to match against the regex`"[_A-Z0-9*{}]+"`. Two cases are possible here:"NAME"is either a plain slice name consisting only of uppercase letters, digits or an underscore character. Or it's a wildcarded slice name, indicated by an asterisk character.
The first variant just expands to the union of all slices named exactly "NAME". The second variant expands to the union of all slices which match against the wildcard pattern "NAME". Here the asterisk has the semantical meaning of none or any number of characters. And there's one special case: when the asterisk is immediately followed by characters enclosed within braces, it means none or any number of characters, but not this sequence of characters.
SLICE_TERM ::= "!NAME" | "~NAME"β The complement of sliceNAME(i.e.ALL\NAME).
In formula: {x in ALL: x not in NAME}
SLICE_TERM ::= "NAME1xNAME2", "NAME1^NAME2"β The exclusive-or relation between sliceNAME1and sliceNAME2. In set theory this is also called symmetric difference:(NAME1uNAME2)\(NAME1nNAME2)or alternatively(NAME1n!NAME2)u(!NAME1nNAME2).
In formula: {x in ALL: (x in NAME1 or x in NAME2) and not (x in NAME1 and x in NAME2)}.
SLICE_TERM ::= "NAME1\NAME2", "NAME1-NAME2"β The difference of sliceNAME1and sliceNAME2, i.e.NAME1minusNAME2.
In formula: {x in ALL: x in NAME1 and x not in NAME2}
SLICE_TERM ::= "NAME1nNAME2" | "NAME1%NAME2"β The intersection of sliceNAME1and sliceNAME2.
In formula: {x in ALL: x in NAME1 and x in NAME2}
SLICE_TERM ::= "NAME1uNAME2", "NAME1+NAME2"β The union of sliceNAME1and sliceNAME2.
In formula: {x in ALL: x in NAME1 or x in NAME2}
SLICE_TERM ::= "(" SLICE_TERM ")"β A grouped slice term. Use this to force a different order of evaluation. By default, all operators are left-associative, except complement, which is right-associative. Operators are listed below from lowest to highest precedence:
- u x n !
π Advanced Selection: Slice Levels π
Because slices can be overlapping and stacked, a definition level is assigned to each slice while the input is parsed. These levels range from 1 to the maximum encountered (level 0 is the whole file, i.e. "ALL"). When a slice begins, it's assigned the lowest free level, beginning with level 1. As long as one level is in use, it cannot be assigned again until the end delimiter of the corresponding slice is seen. no double-booking, we don't do that here π«Ά
An example:
[A:[B::B]:A][C:[D:[E::C]:D][F::E]:F]
3 E-----------E
2 B--B D--------D
1 A--------A C--------C F-----F
0
So here slice A is assigned level 1. Then B is assigned level 2 because level 1 is still in use by A. Then the end of B is reached, so level 2 is freed. Then the end of A is reached and level 1 is also free now, so C gets assigned level 1 again. Now only level 1 is in use, so D is assigned level 2. Then E is assigned level 3. Then the end of C is seen and level 1 freed. Then the end of D is seen and level 2 is freed. Now F begins and because only level 3 is in use, it gets level 1 assigned. Then the end of E frees level 3 and the end of F frees level 1. Finally no levels are still in use. That right there? That indicates the slicing is correct. slay π
If there are any used levels left at the end of this process, that indicates an input error, and slice responds with an error message displaying the still-open slices.
This complicated level mechanism is needed for granular set operations where particular slices should be included or excluded only.
So, to make life easier, a few pseudo-slices are automatically defined:
"DEFn"β The union of all user-defined slices at exactly leveln(0 <= n <= oo)."UNDEFn"β The union of all non-user-defined slices at exactly leveln(0 <= n <= oo). This actually is just"!DEFn"."DEF"β The union of all user-defined slices at all levels, beginning at level1. This actually is the union of all"DEFn"slices."UNDEF"β The union of all non-user-defined slices at all levels, beginning with1. This actually is just"!DEF"."ALL"β The whole file. This actually is just"UNDEF0", because at level0there are no user defined slices, so all is undefined.NAME"@"β This is the sliceNAMEminus the union of all"DEFn"slices withmin(NAME) <= n <= oo. Heremin(NAME)is the lowest level plus one whereNAMEever occurred. You can read this as`NAME without all other slices at higher levels which overwrite it`. This sounds a little bit crazy, but actually is the most important construct. Try to understand it or your slice terms become very complicated. fr fr, do not skip this one.
β¨ OPTIONS β¨
[-y outputpolicy]β This flag changes output policy depending on events:"u"when an undefined set is encountered,"w"for an unmatched wildcard set,"z"when output is empty, and"s"if it only consists of whitespace characters. Each letter is followed by a digit telling which action is bound to such events:0to ignore such events,1to display a warning message and continue,2to skip the concerned file and continue, and3to abort with an error message.
This flag consists of one or more events specifications, and the default is "u0w0s0z0".
[-o sliceterm:outputfile[@chmodcmd][#outputpolicy] ..]β This redirects the output to a file. Usually the whole file will be sent to"STDOUT"(same as"ALL:-"). You can use this option more than once to output to more than one file, while the correspondingslicetermdetermines which output data will be included into each output file.
The optional chmodcmd string is intended for specifying options for the chmod command, which is applied to outputfile after writing. For instance use `"a+r"` to make sure the file is readable by a webserver, or `"u+x"` to create a file with the execution bit set (usually used for SSI files on a webserver with the "XBitHack" option available).
The optional outputpolicy string allows changing output policy for only this output file, without changing its global meaning. See above for more information about output policy.
Be careful here: when you use parenthesis or asterisks insideslicetermyou have to make sure it is really passed toslicethis way, i.e. usually you have to escape these characters from interpolation by the used shell. Do this either by adding backslashes in front of these characters or just surround the complete option argument with single quotes (''). π the shell will absolutely eat your asterisks otherwise.
-vβ This sets verbose mode, where some processing information will be given on the console for debugging purposes.-Vβ Displays the version identification string.-hβ Displays the usage page.
β¨ SPECIAL FEATURE β¨
Sometimes it can be very useful to be able to provide command line options directly within the input file β for instance, to set up one or more -o options. For this, slice recognizes lines of the form
%!slice OPTIONS
in the input file, and automatically adds OPTIONS to the argument line options. These lines have to start in column 0. no leading spaces bestie, she's strict about that.
Example:
%!slice -oTOC:contents.txt
β¨ EXAMPLE β¨
Assume the following simple multi-language article file article.src, written in HTML:
<html>
<head>
<title>[EN:Titlepage:][DE:Titelseite:]</title>
</head>
<body>
<center>
<h1>[EN:The Title itself:][DE:Der Titel selbst:]</h1>
</center>
<blockquote>
[EN:...English Abstract...:]
[DE:...Deutsche Zusammenfassung...:]
</blockquote>
[EN:...English Text...:]
[DE:...Deutscher Text...:]
</body>
</html>
The command
slice -o ENuUNDEF:article.html.en -o DEuUNDEF:article.html.de
then creates the following two files:
article.html.en:
<html>
<head>
<title>Titlepage</title>
</head>
<body>
<center>
<h1>The Title itself</h1>
</center>
<blockquote>
...English Abstract...
</blockquote>
...English Text...
</body>
</html>
article.html.de:
<html>
<head>
<title>Titelseite</title>
</head>
<body>
<center>
<h1>Der Titel selbst</h1>
</center>
<blockquote>
...Deutsche Zusammenfassung...
</blockquote>
...Deutscher Text...
</body>
</html>
like, two whole files from one source, no duplication, no drama. that's the whole point and she ate π₯
β¨ RESTRICTION β¨
The current implementation only handles anonymous end delimiters `":]"` correctly in clear cases where no mis-interpretation is possible, i.e. when no overlapping occurs. For instance in
...[A:...[B:...:A]...:]...
the end delimiter is not correctly assigned to the B slice. So, be careful when using anonymous end delimiters in overlapping situations. π
Pure stacking like
...[A:...[B:...:]...:]...
is allowed and handled correctly, but only when you interpret this as
...[A:...[B:...:B]...:A]...
π COPYRIGHT π
ok so legally speaking, bestie, this icon has β¨ownersβ¨:
- Copyright (c) 1997-2002 Ralf S. Engelschall.
- Copyright (c) 1999-2002 Denis Barbier.
that's it, that's the whole thing, no cap. two names, two date ranges, one legendary tool. periodt. π
πΈ SEE ALSO πΈ
if you wanna go straight to the source (and honestly? slay, do that), the Slice Home is right here:
- Slice Home: http://www.engelschall.com/sw/slice/
that's the link, that's the vibe. go say hi to it. π¦
π AUTHORS π
these are the main characters who made this whole thing happen, show some respect fr fr:
- Ralf S. Engelschall
rse@engelschall.comwww.engelschall.com
- Denis Barbier
barbier@engelschall.com
two absolute legends, one legendary slice. we love to see it. π
okay bestie that's the whole page, you made it to the end, iconic behavior honestly π«Άπ
this lil beauty comes from the fine folks at EN Tools, dated 2020-11-29, and it lives in the manpage section known as SLICE(1). go forth and slice, queen. β¨πΈπ
π¦ where this page comes from
- debian bookworm: slice 2.32.0~ds1-1 Β· GPL-2.0-or-later
- debian trixie: slice 2.32.0~ds1-1 Β· GPL-2.0-or-later
- ubuntu jammy: slice 2.32.0~ds1-1 Β· GPL-2.0-or-later
- ubuntu noble: slice 2.32.0~ds1-1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms