How should we use sed?

Question

The introduction that we have of sed is brief. Is it only used to replace text in files or should we also use it in other circumstances?

Answer

sed is a programming language in its own right so there is a lot more to it than search and replace. With that being said, however, it is good enough at this stage to simply use sed as an extension of grep which also enables you to edit the matches that you find. In that way, we use sed as follows

sed "s/match/replace/g" file

Note that like grep, sed also can have arguments that change its behavior.

9 Likes