Day 26: sed and Substitution Patterns

I have been going through the manual for sed and was also practicing how to use the substitution command in Vim. I can’t wait until I get the hang of these tools. My efficiency keeps going up. It’s exciting for sure.

TLDR;

Okay, so here are the highlights of what I did:

  • I continued to study and write notes on the sed program. I haven’t used it for anything practical just yet but I have started looking into sed scripts and their syntax.
  • I watched a few videos on the awk program and some practical applications of these programs.

Interesting substitution commands I wrote:

# 1. Remove all the white space preceding a <tr> tag that is misaligned. This pattern uses the Vim substitution syntax for lookaheads
:s/\s\+\(<tr\)\@=/    /gc
# 2. Replaces all flags (e.g. -a) written in the paragraph with the markdown backticks (i.e. `-a`).
:s/-\([a-z]\)\(\s\)\@=/`-\1`/gc

For example if I had some text like this:

Without -e or -f options, sed uses the first non-option parameter as the script, and the following non-option parameters as input files. If -e or -f options are used to specify a script, all non-option parameters are taken as input files. Options -e and -f can be combined, and can appear multiple times (in which case the final effective script will be concatenation of all the individual scripts).

It would turn out like this, after running Substitution #2:

Without -e or -f options, sed uses the first non-option parameter as the script, and the following non-option parameters as input files. If -e or -f options are used to specify a script, all non-option parameters are taken as input files. Options -e and -f can be combined, and can appear multiple times (in which case the final effective script will be concatenation of all the individual scripts).

Conclusion

That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!