comparing files
Juanita is a highly experienced and competent RHEL Sysadmin at Red Hat. She want compare 3 files and find ALL developers who are in all 3 files:
- kubernetes_instructors.txt
- linux_instructors.txt
- mariadb_intructors.txt
She wants to add all developers in all 3 files to a new file called have_kubernetes_linux_and_mariadb_expertise.txt so that she can email them and have them start developing lesson plans for an upcoming Kubernetes-Linux-MariaDB Intregration Training Week.
Please list and explain all comm commands that Juanita will need to issue to complete project.
Juanita can use the comm
command to find the lines that are common in all three files and create a new file with their names. Here are the commands she will need to issue:
- Change the current working directory to the directory where the three files are located.
- cd /path/to/files
- Use the
comm
command to find the lines that are common in all three files.- sudo comm -12 <(sort kubernetes_instructors.txt) <(sort linux_instructors.txt) <(sort mariadb_instructors.txt) > common_instructors.txt
The
comm
command compares two files line by line and outputs the lines that are common to both files. We need to run thecomm
command three times to compare all three files.The
-12
option suppresses lines that are unique to the first or second file, and only shows the common lines in both files. The<()
syntax is a process substitution that allows us to sort the files before passing them to thecomm
command.The
>
operator redirects the output to a file calledcommon_instructors.txt
.
- Create a new file called
have_kubernetes_linux_and_mariadb_expertise.txt
and copy the contents ofcommon_instructors.txt
to it.- sudo touch have_kubernetes_linux_and_mariadb_expertise.txt
- sudo cp common_instructors.txt have_kubernetes_linux_and_mariadb_expertise.txt
- Email the instructors whose names are in the new file using the
mail
command or any other preferred email client.
Overall, the commands that Juanita will need to issue are:
- cd /path/to/files
- sudo comm -12 <(sort kubernetes_instructors.txt) <(sort linux_instructors.txt) <(sort mariadb_instructors.txt) > common_instructors.txt
- sudo touch have_kubernetes_linux_and_mariadb_expertise.txt
- sudo cp common_instructors.txt have_kubernetes_linux_and_mariadb_expertise.txt