Saving Changes
Learn how to save changes in a file after making changes with the sed command.
We'll cover the following
Redirection
In the previous lesson, we learned how to edit text using sed
. Now, we’ll learn how to save those changes. To keep the changes we’ve made with sed
, we have two options. Our first option is to redirect the output to a new file using redirection.
Let’s run the terminal below to execute the following command to transform all instances of very
to really
and save the results to the file new_document.md
:
cat << 'EOF' > document.md
This is *very* important text with *very* important words.
* These words are not important.
* Neither are these.
You can *always* tell very important text because it's in italics.
EOF
sed -e 's/very/really/g' document.md > new_document.md
cat new_document.md
Run the complete code on the terminal below for practice.
Get hands-on with 1400+ tech skills courses.