I learned how to:
In this task, I used the tee command to display the output to both the screen and a file.
The tee command reads the standard input. In this example, the standard input is hostname. The tee command outputs the hostname to the screen (in the shell) and the designated file, which is file1.txt.
The output from the command hostname | tee file1.txt was ip-10-0-10-81.us-west-2.compute.internal.
From the following output, I could see the standard input for tee in the output of the command hostname. The tee command wrote the hostname to the file1.txt and to the screen.
To confirm that the file1.txt file had been created, I entered ls and pressed Enter.
In the current directory, there are two items present: companyA and file1.txt
In this task, I used the sort command to reorder the list within the test.csv file. I also used the pipe operator to search for the factory in Paris.
The output looked like the following image. Because I used the sort command with no options, it sorted the list with the default action by alphabetical order, which is why Factory is listed before Stores. The command then sorts by numerical order.
When the command sort test.csv was ran, it sorted the contents within the file in the following order: Factory 1 Paris, Factory 3 Brasilia, Factory 5 Tokyo, Store 2 Dubai, and Store 4 Algiers.
To look for the factory named Paris using the pipe (|) operator, I entered find | grep Paris test.csv and pressed Enter.
In the following output, find | grep Paris test.csv searches and lists the content of the test.csv file and redirects the results to the grep command where it searches for the Paris pattern.
When the command grep Paris test.csv is ran, it searches for the word Paris and returns the following: Factory, 1, Paris.
In this task, I used the cut command to edit the test.csv file.
As I could see from the following output, the cut command removed everything after the ,.
After the cut command is ran, the following is left: Dallas, Seattle, Los Angeles, Atlanta, and New York.
I was tasked to use only the sed command to make changes or do all the changes in one line. (I could use command chaining using the pipe character (|).)
I remembered that the sed command is mainly used to replace some text in a file for different text.
The sed command searches the file text for an occurrence of the first string, and will replace any matches with the second.
I used the sed command to replace the first comma (,) with periods (.) in both the cities.csv and test.csv files.
Output: