📝 Text & Pipes
Text & Pipes: The Linux pipe (`|`) connects the standard output (stdout) of one process directly to the standard input (stdin) of the next, building a data-processing pipeline fr
The Linux pipe (`|`) connects the standard output (stdout) of one process directly to the standard input (stdin) of the next, building a data-processing pipeline from small, single-purpose tools without any intermediate files. Think of it the same way Java's Stream API chains operations: `lines.filter(...).map(...).count()` — each step transforms the data and hands it to the next, and no intermediate `List` is ever materialised on disk. But here is the thought experiment: if `grep` already exists as a standalone command, why do we chain it with `cat` and `wc -l` instead of building one big "count matching lines" command? Because composability beats monolithic tools — `grep "FAILED"` is useful alone, combined with `wc -l` it counts failures, combined with `sort | uniq -c` it ranks them by frequency, and none of those combinations require a new command to be written. For QA work in CI this is the difference between manually opening a 50,000-line test log in an editor and running `grep "ERROR" test.log | grep -v "ExpectedError" | wc -l` in two seconds to get an exact failure count — the pipe chain is your command-line Stream API, and every QA automation engineer should be able to build one without looking up the syntax.
Searching Text — grep
Decide the search term
We are searching for "timeout" but the log may have variants like "Timeout" or "TIMEOUT".
Make it case-insensitive with -i
grep -i "timeout" app.log now matches regardless of upper/lower case.
Add line numbers with -n
grep -in "timeout" app.log output now starts with the line number, like 12:Connection timeout after 30s.
Every matching line is listed on its own line; if there is no match, grep prints nothing and returns exit code 1.
grep -in "timeout" app.log | wc -l lets you count how many timeout errors there are in one line.
Order the process of doing a case-insensitive search in a log file and finding it with line numbers.
Decide the search word: "timeout"
Add the -i flag: ignore case
Add the -n flag: show line numbers