Write a seed command which will take a data file. data. in containing only numbe
ID: 3805207 • Letter: W
Question
Write a seed command which will take a data file. data. in containing only numbers and strip off the first number of each line, writing the result to the file data. out. There may or may not be white space before the first number and all of the white space after the first number should be stripped. the seed command should be entirely on the command line. You are running ports entry which will detect top and up connection attempts at a number of ports and will block connections from those sites. You want a list of all TCP and UDP connection attempts not to TCP port 80 from scanner.cs.utsa.edu and since they are logged in/vary/log/messages you want a seed script to print out the date, sc2umer.cs.utsa.edu. the connection type (TCP or UDP) and the port. If the input looks like: Mar 5 09:16:56 attack alert: Connect from: sc2umer.cs.utsa.edu to TCP port: 635 Mar 5 10:29:21 admiralty: Going into listen mode on TCP port: 4000 Mar 5 12:36:18 attack alert: Connect from: sc2umer.cs.utsa.edu to TCP port: 80 Mar 5 16:32:31 attack alert: Connect from: 129.115.11.71 to UDP port: 137 Mar 5 16:35:13 attack alert: Connect from: sc2umer.cs.utsa.edu to UDP port: 137 Mar 5 19:17:09 attack alert: Connect from: 129.115.11.57 to TCP port: 1080 Mar 5 19:17:26 attack alert: Connect from: ten43.cs.utsa.edu to TCP port: 79 then the output should look like: Mar 5 09:16:56 scanner.cs.utsa.edu TCP 635 Mar 5 16:35:13 scanner.cs.utsa.edu UDP 137 Notice that only lines with attack alert have information to be printed. Write the seed script!Explanation / Answer
Solution for problem 1:
sed -E 's/^[[:space:]]*[0-9]*[[:space:]]*//g' data.in > data.out
the s - command is used to replace a string of line in sed when it finds the pattern "^[[:space:]]*[0-9]*[[:space:]]*", without quotes with "". This effectively removes the unwanted data from the file.
The redirection operator ">" redirects the output of "sed" to a file, data.out.
Solution for problem 2:
sed -n 's/attackalert: Connect from: [^ ]* to //gp' log | sed 's/port: //g'
The -n flag does not print by default. The "p" explicitly asks the matching pattern to be printed.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.