pesubst(1)

πŸ“¦
this version Β· 2 versions
, in debian bookworm, debian trixie, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing

πŸ’… 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 πŸ‘‘
  • -s pattern β€” 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 -ms flag). slurp slay πŸ“
  • -d pattern β€” the destination (replacement) string. this can be any valid string Perl accepts. for the deets, go read the perlre(1) manpage, she's thorough fr fr πŸ“–
  • -m modifiers β€” 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