Question
1. The last command lists information about who has logged into the computer on which it is run. In particular, it has a column with
1. The last command lists information about who has logged into the computer on which it is run. In particular, it has a column with the username, the terminal on which the user was connected, the internet address (the IP address) from which they connected to the computer, and the date and time that they logged in and then logged out if they did. If they logged out it also displays the total time they were logged in. For example, this is an entry for me on cslab12: sweiss pts/11 146.95.214.131 Thu Sep 14 13:05 - 14:27 (01:22) If the username is too long it is truncated, but there are options to display the full username. For this exercise you are to write a bash script named logincount that takes a list of usernames as its command line arguments and displays on the screen, for each user name, a message of the form Number of times that . 2. A DNA string is a sequence of the letters a, c, g, and t in any order. For example, aacgtttgtaaccag is a DNA string of length 15. Each sequence of three consecutive letters is called a codon. For example, in the preceding string, the codons are aac, gtt, tgt, aac, and cag. If we ignored the rst letter and started listing the codons starting at the second a, the codons would be acg, ttt, gta, and acc, and we would ignore the last ag. The letters are called bases. A DNA string can be hundreds of thousands of codons long, even millions of codons long, which means that it is infeasible to count them by hand. It would be useful to have a simple script that could count the number of occurrences of a specic codon in such a string. For instance, for the example string above such a script would tell us that aac occurs three times and tgt occurs once. More generally, we want to be able to nd occurrences of arbitrary sequences of bases in a given DNA string, such as how many times ttatg occurs, or how many times cgacgattag occurs. Your job is to write a script named countmatches that expects at least two arguments on the command line. The rst argument is the pathname of a le containing a valid DNA string with no newline characters or white space characters of any kind within it. (It will be terminated with a newline character.) This le contains nothing but a sequence of the letters a, c, g, and t. The remaining arguments are strings containing only the bases a, c, g, and t in any order. For each valid argument string, it will search the DNA string in the le and count how many non-overlapping occurrences of that argument string are in the DNA string. To make sure you understand what non-overlapping means, the string ata occurs just once in the string atata, not twice, because the two occurrences overlap. If your script is called correctly, it will output for each argument a line containing the argument string followed by how many times it occurs in the string. If it nds no occurrences, it should output 0 as a count. For example, if the string aaccgtttgtaaccggaac is in a le named dnafile, then your script should work like this: $ countmatches dnafile ttt ttt 1 $ countmatches dnafile aac ggg aaccg aac 3 ggg 0 aaccg 2 Warning: if it is given valid arguments, the script is not to output anything except the strings and their associated counts. No fancy messages, no words! The script should check that the rst argument is a le name and that there is at least one other argument after it. If the rst is not a le name or if it is missing anything after the lename, the script should print a how-to-use-me message and then exit. It is not required to check that the le is in the proper form, or that the string contains nothing but the letters a, c, g, and t. Hint: You can solve this problem using grep and one other command that appears in this document. Although there are other lters, you do not need them to solve this problem. You have to read more about grep to know how to use it. The other command has appeared in the slides already.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started