pesubst(1)
π pesubst(1) β the hxtools glow-up of stream substitution β¨
okay bestie, sit DOWN, because this little hxtools baddie is about to replace sed(1) in your heart π
πΈ NAME πΈ
pesubst β perl-regexp stream substitution, aka the moment your regexes stopped being mid π§
β¨ SYNTAX β¨
pesubst [-f] [-s pattern] [-d pattern] [-m modifiers] file...
π¦ DESCRIPTION π¦
so pesubst substitutes strings in streams and files, and it does it using the Perl engine β yes, THE Perl engine, the main character of regex π
it obsoletes sed(1) for simple substitution tasks. not me saying your fave is over, but likeβ¦ it is π
π OPTIONS π
-fβ fill the replacement string with NULs to bring it up to the size of the original string. yes literally pad it out, she's giving consistent byte counts π-spattern β the source pattern to search for in files. this can be any valid Perl regular expression. files get slurped in as a whole, so matching across newlines should be no problem at all (with the-msflag). slurp slay π-dpattern β the destination (replacement) string. this can be any valid string Perl accepts. for the deets, go read theperlre(1)manpage, she's thorough fr fr π-mmodifiers β a string of modifiers to apply to the regex. see below, bestie, they're right there β¬οΈ
π MODIFIERS π
eβ evaluate the right side as an expression. code brain activated π§gβ replace globally, i.e., all occurrences. this is always enabled in pesubst, so don't even worry about it, she does it every time πiβ do case-insensitive pattern matching.FOO?foo?FoO? all the same to her πmβ treat the string as multiple lines. that is, change"^"and"$"from matching the start or end of the string to matching the start or end of any line anywhere within the string. multi-line main character energy πoβ compile pattern only once. efficiency icon βsβ treat the string as single line. that is, change"."to match any character whatsoever, even a newline, which normally it would not match. she's greedy like that π«Άxβ extend your pattern's legibility by permitting whitespace and comments. pretty patterns, pretty mind β¨
π₯ EXAMPLES π₯
change all occurrences of foo (case-insensitive) to bar:
pesubst -s foo -d bar -ms myfile
change all Shell-style comments into C++ ones:
pesubst -s '^#' -d // -mm myfile
using both the "m" and "i" flags:
pesubst -s '^#INCLUDE\s+' -d '#include ' -mmi myfile.c
π SEE ALSO π
hxtools(7), pegrep(1) β go read them, iykyk π
ngl if you're out here hand-rolling sed one-liners in 2008-era tooling when pesubst exists, that's a vibe check you're failing π
and that's the whole page, bestie β brought to you by hxtools, dated 2008-02-06, no cap. go substitute something iconic π β¨π¦
π¦ where this page comes from
- debian bookworm: hxtools 20221119-1 Β· MIT
- debian trixie: hxtools 20231224-2+b2 Β· MIT
- opensuse-leap 16.0: hxtools-man 20231224-bp160.1.12 Β· GPL-2.0-or-later AND WTFPL
- ubuntu jammy: hxtools 20211204-1 Β· GPL-2.0-or-later OR GPL-2+3 OR WTFPL
- ubuntu noble: hxtools 20231224-2ubuntu1 Β· MIT
- ubuntu questing: hxtools 20231224-2ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms