FAQ: Redirection - sed

This community-built FAQ covers the “sed” exercise from the lesson “Redirection”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Learn the Command Line

FAQs on the exercise sed

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

It’s sort of a broad and subjective criticism, but I can’t say I’m a fan of the structure of this particular lesson.

The way we get instructed through an exercise and then the beginning text of the next exercise is used to explain what we were doing and why previously just felt a little obtuse to me. Going forward in this course, I’m hoping things are further reiterated or I will surely feel the need to go back and complete the lesson again.

Just my two cents, and thought the final exercise would be the most relevant place to put the comment that I could find.

Having been jumping around different courses and paths based on recommendations, these lessons stood out, and at least for me personally were not nearly as effective as others I’ve undertaken to this point.


$ sed ‘s/snow/rain/g’ forests.txt
The Amazon rainforest
The Congo rainforest
Valdivian Temperate rainforest
Daintree rainforest
Southeast Asian rainforest rainforest
Tongrass National forest
Sinharaja Forest Reserve
Pacific Temperate rainforest rainforest

$ sed ‘s/rain/snow/’ forests.txt
The Amazon snowforest
The Congo snowforest
Valdivian Temperate snowforest
Daintree snowforest
Southeast Asian snowforest snowforest
Tongrass National forest
Sinharaja Forest Reserve
Pacific Temperate snowforest snowforest

Why does not using g here still result in all instances in each line being replaced? I thought g replaced all instances while not using g replaced only the first instance in each line.

1 Like

all instances

You could say that if your input had zero instances, similarly, you don’t have enough instances per line that there is a difference.

@ charlief0xxtrot: because sed isn’t actually permanently changing the content of your file in this instance. After the initial output, the file remains untouched. To modify the behavior of sed to actually change what you edit, you’d add the option “-i”.

1 Like
  • 1 to mikedem’s post

Unlike with other Codecademy courses, I found the structure of this course unhelpful. Explaining concepts AFTER making one use them is in this particular case a very poor idea.


I had no idea what I was typing when I was typing it. And when the concept was finally explained to me, instead of being allowed to practise it, I was asked to move on to the next set of commands that meant absolutely nothing to me.

I found myself typing the required stuff mindlessly just so I could get to the explanation on the next page, and then hit ‘Back’ so I could practise it, but this time knowing what I’m doing.

1 Like