1. Write a regular expression to grep the file /courses/cop3353m-w/quiz2/message
ID: 3704544 • Letter: 1
Question
1. Write a regular expression to grep the file /courses/cop3353m-w/quiz2/messages.out Match all lines that have the word "Connect" in it but not any other series of letters that include Connect. For instance, do not match "Connects". Also, do not match any of these lines that "end" with the word "try". Pipe this to a command to count the amount of matched lines. The result should be "2" Deliverables: Copy/paste command line and output into word or text doc. 2. Write a script named pinger.sh that reads /etc/hosts and matches all lines that have the pattern "ember" and also only return the first column which would be an ip address. The script will need to ping for a count of 1 to each ip address. Then it should output the ip address being pinged as well as the line from the output that matches "packet loss". Refer to participation exercise #21. You will likely use command substitution and an awk command. Your output should look like the below: [cnavaember ]S sh pinger.sh pinging 10.200.208.100 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.101 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.102 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.103 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.104 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.121 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.122 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.123 1 packets transmitted, 1 received, 0% packet loss, time 0ms pinging 10.200.208.125 1 packets transmitted, 1 received, 0% packet loss, time 0msExplanation / Answer
1) grep -v "try$" file | grep 'Connect' | wc -l
grep -v "try$" ignores line ending with "try"
| pipes the previous output to grep 'Connect' as Input which find lines with word Connect,
finally wc -l, counts the number of lines.
Ex: Connect to the connects in to connect Connect
Connect try
Connect
Connect
O/p: 3
2)
for i in $(grep 'ember' file | awk '{print $1}');
do ping "$i"; done
where file contains the input.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.