sed command do in Linux?sed is a stream editor used to perform basic text transformations on an input stream (a file or input from a pipeline).
sed substitution command.The basic syntax is sed 's/pattern/replacement/' filename. It replaces the first occurrence of pattern with replacement on each line.
sed?Add the g flag at the end: sed 's/pattern/replacement/g' filename. This replaces every match on each line.
sed 's/cat/dog/g' file.txt do?It replaces every occurrence of the word cat with dog in each line of file.txt, printing the result to the screen.
sed substitution back to the original file?Use the -i option for in-place editing: sed -i 's/old/new/g' filename. This updates the file directly.
g flag do in a sed substitution?The g flag means global replacement on each line, changing all matches, not just the first.
fruits.txt?Without the g flag, only the first occurrence per line is replaced.
sed substitution and save changes directly to the file?The -i option edits the file in place, saving changes directly.
sed 's/blue/red/2' colors.txtThe number after the substitution command specifies which occurrence to replace on each line.
/ in sed substitution?You can use other delimiters like # to avoid escaping slashes in patterns.
sed to replace all occurrences of a word in a file and save the changes.sed 's/pattern/replacement/' and sed 's/pattern/replacement/g'.