This community-built FAQ covers the “|” exercise from the lesson “Redirection”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Learn the Command Line
FAQs on the exercise |
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in #get-help.
Agree with a comment or answer? Like () to up-vote the contribution!
Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.
Looking for motivation to keep learning? Join our wider discussions in #community
Learn more about how to use this guide.
Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting
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!
I have a question concerning my comprehension of the | effect here…
cat volcanos.txt | wc outputs the number of lines, words and characters in volcanoes.txt (I understand that).
cat volcanoes.txt | wc | cat > islands.txt (from what I understand, cat islands.txt output became volcanoes.txt | wc output).
Is that correct, and especially is it a good way to say it? - sorry I try to understand by verbelazing the concept.
Thank you for your answer.
I think you are right.
How I would phrase it is:
cat volcanoes.txt | wc : the content of volcanoes.txt is provided to the command
wc by the pipe, which provides the number of lines, words and characters of the provided content. Other way more complicated to say it:
- “stdin” of
cat is the file volcanoes.txt.
- “stdout” of
cat volcanoes.txt is the content of the file volcanoes.txt
- “stdin” of
wc is the “stdout” of
cat volcanoes.txt (because of the pipe).
- “stdout” of
cat volcanos.txt | wc is the number of lines, words and characters of the content of the file volcanoes.txt.
cat volcanoes.txt | wc | cat > islands.txt : the “stdout” of
cat volcanos.txt | wc is the new input of the second
cat wich is then redirected to the file “island.txt” through the
> command (i.e. the content of “island.txt” is replaced by the output of the second cat, here the number of lines, words and characters of the content of the file volcanoes.txt)
Why to use the second
cat volcanoes.txt | wc | cat > islands.txt?
Why not simply put
cat volcanoes.txt | wc > islands.txt?
Thank you for your answer. I am not familiar yet with all that but I think you answered my question.
I understand but it is still not “natural” for me, like a language that I am learning (that is what I am doing actually) but do not master at all yet, I am far from fluent.
And concerning your “Why” in your second message it is simply because the exercice explained the redirections this way.
Thank you again
I am questioning the same thing. Anyone?
I have tested it on my system and you are right. It would have the exact same effect in a more efficient way. I believe they just presented it this way to illustrate that double piping is possible. As the command for piping | could not be directly followed by the command to redirect > it is necessary to open the output of ‘cat volcanoes.txt | wc’ again so it could then be redirected to islands.txt, therefore definitely a redundancy. That’s my understanding but I’m no expert, so take it with a grain of salt!!
Why is the
man command disabled (or excluded) in the interactive shell? I would hazard to say that this is a pretty basic program that should be included for students learning unix based systems.
It is especially helpful to use when looking up the format of the
I was confused about the differences between piping and redirection. This article helped a lot
Not sure if anyone is still confused, but i realised that the command
cat > island.txt
creates a file called island.txt in your current directory.
If you try this line of code, your usual $ sign goes missing on the left side, in order for the user to type in the content of the new txt file manually, until they press the CTRL+D keys, to exit. you can try this and cat island.txt to see the new content of your created file.
So to break it down:
cat volcanoes.txt | wc → this has an output of the wordcount of the content of volcanoes.txt,
cat > islands.txt → this creates a new file and waits for User input for the content of said new file
cat volcanoes.txt | wc | cat > islands.txt → by combining the two, you input the content of the New file, as the wordcount of the volcanoes.txt
Hope this helps!
user [codedcolt0961340047]'s link helped! check it out if still unsure.
Im a noob when it comes to this, so if im wrong, lmk!
edit: not sure why, but seems like
cat volcanoes.txt | wc > islands.txt → also creates the new file. Then im not sure about the functionality of the last “cat” too
It’s totally unnecessary, I don’t think there’s a good reason for it other than maybe the author felt it more explicitly showed what was going on.
This article is worth reading if you are questioning why this would be used.
The sed command is replacing the first four instances of the word for me. Why?
That is seems like a different problem to those above but what
sed is doing there is replacing only the first appearance of “snow” with “rain” on each new line. Perhaps you want
sed 's/pattern/replacement/g' to substitute all appearances in a line?
HI I’m trying to set up my computer to use the pipe command in the Command Line tutorial here is an excerpt from the lesson REDIRECTION
| is a “pipe.” The
| takes the standard output of the command on the left, and pipes it as standard input to the command on the right. You can think of this as “command to command” redirection.
I have not been successful after following the instructions in the link provided here My keyboard does not allow me to type a character used in a Codecademy lesson. What should I do?
Please can you help?
I can’t promie anything but the easiest route might be to see if there’s some way to copy-paste the symbol. Whilst the standard keypresses like (ctrl-v) or (cmd-v) are interpreted by the console window the browser you’re using normally has a way to paste regardless.
Try a right click to see if there’s a paste option (after copying the pipe symbol) or try using the drop-down menu near the top (e.g. Edit → paste).
Long term you might want to spend some time looking for a way to input this character normally. Exactly how to do this may depend on your operating system (e.g. Windows might use alt-codes and linux might use the Compose key and the
Alt Gr and
Fn keys also provides extra options on many systems). You should be able to find at least one method to input extended characters on basically all operating systems. You will likely need to spend a little time on a web search for your specific operating system to find the right guidance.
As a last resort many operating systems offer routes to change the keyboard set-up (either changing it to a different nationality of offering more precise customisation). I think the other options may be preferable to this.
Thanks for your help much appreciated.
For anyone who doesn’t understand what WC’s 3 columns are doing because codeacademy doesn’t explain:
it makes the first column the line count, second is the word count, and the third the character count. Not sure why they introduced two new topics without explaining what the other did.
How to Use the “wc” Command in Bash?.