In: Computer Science
3) Write the awk command that would show the user wmorales (or yourself) that is online (you have to use a pipe) Output, depending on the system that you are using or the command to find the users online, but it would be similar to:
wmorales pts/37 10.32.9.93 13:58 1.00s 0.15s 0.10s w
or
wmorales pts/8 2020-04-25 12:22 (c-71-59-237-122.hsd1.or.comcast.net)
YOUR AWK COMMAND:
(10 points hard one) -
4) use who to show the the users on our system that have the letter r in their first name, OR last name, but nowhere else. Note also that the r can be r or R. Note that your output will be a bit different as well, but note that the uses listed do have r either on their first or last name
output would be similar to:
Outcyrus.rice pts/21 2017-10-23 12:38 (jamess-iphone-2.wifi.pcc.edu)
tina.olsgaard pts/29 2017-10-23 12:41 (174-25-110-78.ptld.qwest.net)
rachel.benes pts/30 2017-10-23 12:54 (laptop-2j35sntl.wifi.pcc.edu)
rachel.benes pts/33 2017-10-23 13:43 (laptop-2j35sntl.wifi.pcc.edu)
jarod.morrow pts/35 2017-10-23 12:54 (sytc310-08.ad.pcc.edu)
wmorales pts/37 2017-10-23 13:58 (10.32.9.93)
----------------------- cut ------------------
note: the letter r or R has to appear either in their first name or last name only, not on the name of the machine that they are using if it happen to have r in it.
YOUR AWK COMMAND:
5) (3 points - easy) from the file called winelist extract a list of wines that cost less than $7.00 output (
it may be different depending the time you do it):
1977 6.99 Franciscan
1977 6.75 Alexander Valley
1977 5.99 Charles Krug
YOUR AWK COMMAND:
SOLUTION:
The Following solution has been implemented on an Ubuntu Linux Box installed on VMware Workstation.
For the purpose of implementation, the following users have been created, in addition to the root User.
1. wmorales
2. Rambo
3. arun
4. danny
Also a file “winelist” has been created containing a list of wines in the prescribed format for Question 5.
Question 3: Write the awk command that would show the user wmorales (or yourself) that is online.
Use the following command,
who | awk ‘/wmorales/ {print}’
Note:
1. The who command displays the users currently logged in.
2. The Pipe ( | ) symbol is used to pass on the output of “who” as input to the next command “awk”.
3. The ‘/wmorales/’ part of the awk command is a pattern match for the word wmorales.
4. The {print} command part of awk is responsible for printing the filtered output.
Question 4: Show the users on our system that have the letter r in their first name, OR last name, but nowhere else. Note also that the r can be r or R.
Use the following command,
who | awk ‘$1 ~ /[Rr]/ {print}’
Note:
1. The who command displays the users currently logged in.
2. The Pipe ( | ) symbol is used to pass on the output of “who” as input to the next command “awk”.
3. The ‘$1’ instructs only the first column should be searched for matches according to pattern.
4. The ‘~’ symbol is used for pattern matching. Here the ‘[Rr]’ indicates that the matching can be either ‘R’ or ‘r’.
5. The {print} command part of awk is responsible for printing the filtered output.
Question 5: From the file called winelist extract a list of wines that cost less than $7.00.
Use the following command,
cat winelist | awk -F ‘ ‘ ‘$2<7.00’
Note:
1. The “cat” command prints the contents of the file “winelist”.
2. The Pipe ( | ) symbol is used to pass on the output of “cat” command as input to the next command “awk”.
3. The “ -F ‘ ‘ “ part of the command is used to specify a delimiter using which you can process specific columns. Here the delimiter is “single space”.
4. The ‘$2<7.00’ part accesses the second column and checks if the value is less than 7.00.
5. The {print} command part of awk is responsible for printing the filtered output.
Hope this helps. Kindly get back to me for clarifications if any.