Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In linux: INSTRUCTIONS: Demonstrate using regular expressions with the grep command to filter text by completing the tasks below. You will also be required to

In linux:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

INSTRUCTIONS: Demonstrate using regular expressions with the grep command to filter text by completing the tasks below. You will also be required to complete tasks previous covered in prior sections and in class. Perform the task being requested on your vSphere virtual machine. Provide the requested answer or screenshot as indicated in the task. TASK Task 1 INFO 1111: Linux INFO-1111: LINUX Read the handout on accessing the Virtual Lab folder on Canvas to access your virtual machine. Log in to the sysadmin account with the password netlab123 and open the terminal program. Task 2 Find the user yadams in the /etc/passwd file, using the command, grep wadams /etc/passwd Task 3 Find all instances of nologia in the /etc/passwd file. Provide the command you used below. Your answer below: Task 4 Find all the instances of localhost in the /etc/hosts file. Provide the command you used below. Your answer below: Task 5 Piping the output of grep to a command or having another command pipe to grep is very common. Count the number of instances of nologio in the /etc/passwd file by executing the command, grep nologin /etc/ passwd | wc-1 How many instances of nologin are in the passwd file? Your answer below: Task 6 Count the number of instances the user sysadmin is in the /var/log/secure file. Provide the command you used below. Your answer below: INFO 1111: Linux INFO-1111: LINUX 4 Task 7 Create a file called mydata.db with the following list. Fred apples 20 Susy oranges 5 Mark watermellons 12 Robert pears 4 Terry oranges 9 Lisa peaches 7 Susy oranges 12 Mark grapes 39 Anne mangoes 7 Greg pineapples 3 Oliver rockmellons 2 Betty limes 14 Task 8 Pipe the output of the cat command to grep to filter for oranges in the mydata.db file, using the command, cat mydata | grep oranges Task 9 Pipe the output of the dmesg command (display changes and and access to hardware device) to grep to find a instances where sda (the first hard drive) is referenced. Use the command, dmesg | grep sda Task 10 Pipe the output of the df -h command to filter only the instances of tmpfs. Provide the command you used below. Your answer below: Task 11 Filter the output of the ps -aux command (list system processes) to only list the processes running bash. (This done similar to tasks 8-10. Provide the command you used below. Your answer below: Task 12 To perform more complex searches with grep we need to use regular expressions (regex). It is recommended to use egrep instead of regular grep when using regex. For instance, perhaps we wanted to filter for both Susy. and Greg from the mydata.db file created in task 7. Use the following command, egrep 'Susy | Greg' mydata.db. The pipe used between Susy and Greg is being used as a regex character by egrep. It is not functioning as a typical pipe which you have used with redirection. Egrep uses a | to represent or. In this case to filter for Susy. or Greg. Explanation of command 1. egrep - a text filtering command that uses regular expressions (regex) 2. 'Susy Greg' - egrep will find all instances of either Susy or Greg 3. mydata.db - The data file. Task 13 Use the concepts in Task 12 to find all instances of apples and oranges from the mydata.db file. Provide the command you used below. Your answer below: Task 14 Find all instances of Anne and Lisa from the mydata.db file. Provide the command you used below. Your answer below: Task 15 To narrow down filters use a. (dot) and a * (asterisk) together. For instance if you would like to only return the line where Susy has 12 oranges and not 5 oranges then use the command, egrep Susy.*12' mydata. db Task 16 Use the concept above to only return the line where Mark has 39 grapes. Provide the command you used below. Your answer below: INFO 1111: Linux Task 17 The -i option with grep or egrep provides a case insensitive search, meaning it will match both lower and uppercase letters. For example, egrep -i 't' mydata, db This returns Terry with an uppercase t and Betty with lowercase t's. Notice this search finds any instance of t regardless of whether it is at the beginning, middle or end of a line. Task 18 The ^(caret) symbol represents the beginning of a line. To search for only the lines that begin with t, use the following command, egrep -i t' mydata.db Task 19 The $ (dollar sign) represents the end of a line. To search for only the lines that end with the number 2, use the following command, egrep 2$' mydata.db Task 21 Regex symbols can be mixed and matched, for example, egrep -i is.*2$' mydata.db. Explain what this command is doing. You can reference other tasks, the chart at the beginning of this assignment or Online resources if needed. Your answer below: Task 22 Find all lines that start with M from the mydata.db file. Provide the command you used below. Your answer below: Task 24 Square brackets [] can be used to match a single character with set letters or numbers. For example to search for any letter y or gor 3, use the command, egrep -i '[y3g]' mydata.dk Task 25 The square brackets can be combined with other regex symbols. For example, egrep -i [st]' mydata, db This will only return lines that start with "s" or "t'. Task 26 The "last" command lists the login in history of your computer system. Enter the last command by typing, last Your current user should show as still logged in. jared@mormon (05:14:01 PM] [/proc] % last jared pts/0 :0.0 jared pts/0 :0.0 jared tty2 jared pts/0 :0.0 reboot system boot 4.9.0-8-amd64 Thu Apr 11 16:30 Thu Apr 11 12:59 Thu Apr 11 12:14 Thu Apr 11 09:40 Thu Apr 11 09:38 still logged in 16:30 TOS:31) still logged in 12:59 (03:18) still running Pipe the last command to egrep and filter only the lines that end with "in". This should produce a list of only the users currently logged in. Provide the command you used below. Your answer below: Task 27 INFO 1111: Linux INFO-1111: Linux 8 From your home directory, pipe the Is command to grep to only list the directories and files that begin with D. Provide the command you used below. Your answer below: Task 28 Pipe the output of the "ip addr" command to grep matching only lines containing the text "inet". This line should contain your ip address. Provide the command you used below. Your answer below: Task 29 Use grep to output the text nameserver from the /etc/resolv.conf file. This file lists your DNS servers. Provide the command you used below. Your answer below: Task 30 Provide a command that will show you how many instances of bash" are in the /etc/passwd file? There are a few ways to do this. There is an option built into grep (see the man page or google) or you can pipe it to a command that will count it for you. Your answer below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions

Question

Describe a persuasive message.

Answered: 1 week ago

Question

Identify and use the five steps for conducting research.

Answered: 1 week ago

Question

List the goals of a persuasive message.

Answered: 1 week ago