grep Chaining
Chaining grep
We can even pass the output from a grep
command to another grep
command to build complex filter chains.
Step One: Get our Dataset
curl -s https://launchcodelearning.org/api/walkthrough/user?data_format=csv
Output:
25000 records is too much.
Step Two: Filter Matches '^John'
Filter data to include only '^John'
:
curl -s https://launchcodelearning.org/api/walkthrough/user?data_format=csv | grep '^John,'
Output:
Step Three: Filter Matches 'Microsoft$'
Using the output from the previous filter, filter further to include lines that match 'Microsoft$'
.
curl -s https://launchcodelearning.org/api/walkthrough/user?data_format=csv | grep '^John,' | grep 'Microsoft$'
Output:
Step Four: Filter Matches @example\.com
Using the output from the previous filter, filter further to include lines that match '@example\.com'
.
curl -s https://launchcodelearning.org/api/walkthrough/user?data_format=csv | grep '^John,' | grep 'Microsoft$' | grep '@example\.com'
Output: