SED Tips


Following on from the last post on removing lines with sed, how do we use sed to substitute output on the fly?



This says substitute occurences of PATT with REPLACE global (or all occurences).

sed 's/PATT/REPLACE/g' filename



So to replace all occurences of Unix with UNIX:

sed 's/Unix/UNIX/g' filename

We can also replace patterns, with variable values, like this:

sed "s/PATT/${THEVAR}/g" filename



[tags]SED, Unix Coding School[/tags]


If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *