Note that in the above solution, contents of search.txt and replace.txt are also processed by the Perl command. Print s/\Q$s/$r/gr' search.txt replace.txt ip.txt If I had known about Perl one-liners, I could have easily utilized find and Bash globs to make my life easier, for example:
Once, I even opened the files as Vim buffers and applied a bufdo command to see if that would make my workflow simpler. I didn’t know about Perl’s options for one-liners, so I used to modify a script whenever I had to do substitutions for multiple files. I used Vim and Perl for all sorts of text processing needs.
#Mac code editor live results multi line substitution how to
My working knowledge of Linux command line was limited at that time and I didn’t know how to use sed or Awk.
One-liners or scripts?įor assembly-level testing of a digital signal processing (DSP) chip, I had to replicate the same scenario for multiple address ranges. However, Perl may have slower performance compared to specialized tools and can be more verbose. Perl has a feature rich regular expression engine, built-in functions, an extensive ecosystem, and is quite portable.
Perl is the most robust portable option for text processing needs. Sometimes you can use Perl either as a single replacement or a complement to them for specific use cases. External commands like grep, sed, Awk, sort, find, or parallel can be combined to work with each other. A shell (like Bash) provides built-in commands and scripting features to easily solve and automate various tasks.