← Terminal to Agents
Terminal to Agents

Joining Tools: The Pipe, grep, and Saving the Answer

14 Sept 2026·6 min read

Until now every command you ran printed its answer to the screen and stopped. Today that changes. You can take what one command produced and hand it straight to another one, and this is the single idea that makes the terminal more than a slow file manager.

First, a tool worth having

grep looks inside files and shows you only the lines that contain the text you asked for. Think of it as Ctrl+F that works on any number of files at once, and can hand its findings to something else.

grep error log.txt
Shows only the lines in log.txt that contain the word error.

That is already the difference between a file with three thousand lines being useless and being answerable. But it gets much better when you stop treating it as the end of the sentence.

The pipe: one character, whole new job

The vertical bar takes whatever the command on its left printed and feeds it into the command on its right, instead of to your screen. Nothing is saved, nothing is changed — the text just flows sideways.

grep error log.txt | wc -l
Instead of showing the error lines, this counts them. wc -l counts lines.
Read a pipe out loudRead the bar as the words "and then". Find the error lines, and then count them. That is the whole grammar. Two commands, neither of which knows the other exists, and together they answer a question neither could answer alone.

This is why the command line survived every app built to replace it. Nobody had to build a tool that searches and counts. Somebody built a tool that searches, somebody else built a tool that counts, and the pipe made them into one thing.

Searching more than one file

grep -r error .
Searches every file inside this folder and everything below it. The dot means "here".

The output changes shape slightly: each line now starts with the filename it came from, then a colon, then the line. That is deliberate — you asked about many files, so it tells you which one each answer belongs to.

And when you want the files themselves rather than what is inside them, that is a different tool:

find . -name "*.txt"
Lists every .txt file under here. The quotes stop the shell from expanding the star too early.

Keeping the answer

A pipe sends output to another command. An arrow sends it to a file instead.

grep error log.txt > errors.txt
Writes the matching lines into errors.txt. Nothing prints on screen.
One arrow replaces, two arrows addA single > overwrites the file completely, with no warning and no confirmation, exactly like rm. A double >> adds to the end and keeps what was there. If you are collecting results over time, you want >>. If you type > by mistake, the old contents are gone.
grep warning log.txt >> errors.txt
Adds to the end of the same file instead of replacing it.
Do this in 60 secondsMake a file: printf and a few lines is fine, or use nano from Part 4 and type three lines with the word test in two of them. Then run grep test yourfile.txt, then grep test yourfile.txt | wc -l, and watch the same command give you a list and then a number. That is the pipe.
Today’s AI angleThis is the exact shape an agent works in. It runs a search, reads what came back, and decides the next command from that result — one thing handing its output to the next. When you get to MCP in Part 11, that idea is still there, just between programs instead of between commands.

You can now ask real questions of your machine. Which means you are ready for the thing that stops most people permanently: the moment a command answers back in red text instead of doing what you wanted.

Joining Tools: The Pipe, grep, and Saving the Answer · Ali Huzaifa