sed
This week, I've been using sed quite a lot. sed is short for stream editor, and is designed to work with large amounts of streaming text.
The most common use case that most people have for sed is text substitution. As it's a stream editor, by default it looks at one line of input at a time.
So for example, given the following input:
Running the following command would replace "number" with "NUMBER".
bash
Just like perl, substitution only affects the first match - you need to be explicit to make it replace all occurrences. In this case, that's by adding the g flag.
bash
So, if we run:
bash
We should see:
Applying this to an existing set of text can be done by feeding filenames into sed and using the -i flag, saying "change in place".
So for example, to replace all occurrences of the word "Dog" with the word "Cat":
bash