Learning machine learning? Try my machine learning flashcards or Machine Learning with Python Cookbook.
Save Output To File In Middle Of Command Chain
The tee
command creates a T-junction in a command pipeline, both saving the standard output of the previous command to a file and passing the standard output onward down the pipeline. It is often useful when we want to see the data at intermediate steps in a command pipeline without interrupting it.
Create Example File With List Of File Names
echo 'data_science.txt' >> files.txt
echo 'data_science.html' >> files.txt
echo 'data_science.csv' >> files.txt
echo 'sales.txt' >> files.txt
echo 'operations.html' >> files.txt
echo 'deep_learning.csv' >> files.txt
View File
cat files.txt
data_science.txt
data_science.html
data_science.csv
sales.txt
operations.html
deep_learning.csv
Create Pipeline With Tees
In this pipeline, we:
cat files.txt
, view all filenamestee all_files.txt
, save all filenames to filegrep data_science
, view only filenames withdata_science
in filenametee data_science_files.txt
, save all data science filenames to filegrep .csv
, view only filenames with.csv
in filenametee data_science_csv_files.txt
, save all data science csv filenames to file
cat files.txt | tee all_files.txt | grep data_science | tee data_science_files.txt | grep .csv | tee data_science_csv_files.txt
data_science.csv
View File With All Filenames
cat all_files.txt
data_science.txt
data_science.html
data_science.csv
sales.txt
operations.html
deep_learning.csv
View File With Data Science Filenames
cat data_science_files.txt
data_science.txt
data_science.html
data_science.csv
View File With Data Science CSV Filenames
cat data_science_csv_files.txt
data_science.csv