In this step, you will use the grep command to extract the lines containing the word "Host" from the scan.grep file that you created in the previous step. These lines contain the IP addresses of the scanned hosts. You will then save the extracted lines to a new file named hosts.txt.
The grep command is a powerful tool for searching text files for specific patterns. In this case, you are using it to find lines that contain the word "Host".
The > symbol is used for output redirection. It takes the output of the grep command and saves it to the specified file (hosts.txt). If the file already exists, it will be overwritten.
Let's break down the command:
grep "Host" scan.grep > hosts.txt
grep: This is the command to search for a pattern in a file.
"Host": This is the pattern that you are searching for. In this case, you are searching for lines that contain the word "Host".
scan.grep: This is the file that you are searching in.
>: This is the output redirection operator. It takes the output of the grep command and saves it to the specified file.
hosts.txt: This is the file that you are saving the output to.
Now, let's execute the command in the LabEx VM. Ensure you are in the ~/project directory. If not, navigate to it using:
cd ~/project
Next, run the grep command to extract the IP addresses and save them to the hosts.txt file:
grep "Host" scan.grep > hosts.txt
This command will search the scan.grep file for lines containing "Host" and save those lines to a new file named hosts.txt.
After the command is complete, you can verify that the hosts.txt file has been created in your ~/project directory. You can use the ls command to list the files in the directory:
ls -l
You should see hosts.txt in the list of files.
You can also view the contents of the hosts.txt file using the cat command or a text editor like nano:
cat hosts.txt
or
nano hosts.txt
The output will be a text file containing the lines from scan.grep that include the word "Host". These lines will contain the IP address of the scanned host.