Question

How do you write a perl script called myscript.pl to determine how many logins occurred for...

How do you write a perl script called myscript.pl to determine how many logins occurred for user "abc123456" from myusersfile.txt?

content in mysuerfile.txt are user id "abc123455", user id "abc123456" and user id "abc123457". But we want to know how many times did user id abc123456 login the system.

Homework Answers

Answer #1

Executable Code:

my $file = 'myusersfile.txt';
my $word= 'abc123456';
$count =0;
# Open the file
open my $fh, '<', $file or die "Could not open '$file' $!\n";
# Read each line
while (my $row = <$fh>) {
chomp $row;
# If abc123456 found
if ($row eq $word) {
#Increment count
$count++;
}
}
print "The number of logins for user abc123456 is ";
print $count;
print "$!\n"

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The first script you need to write is login.sh, a simple script that you might run...
The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of...
Finally, write a script named word_counts.sh that prints out how many words are on each line...
Finally, write a script named word_counts.sh that prints out how many words are on each line of standard input, as well as the total number of words at the end. The script should take no arguments. Instead, the script must work by reading every line of standard input (using a while loop) and counting the number of words on each line separately. The script is intended to work with standard input coming from a pipe, which will most often come...
(At least) How many times did endoskeletons arise, and how do we know? (Topic: Deuterostomes/Echinoderms)
(At least) How many times did endoskeletons arise, and how do we know? (Topic: Deuterostomes/Echinoderms)
PYTHON- write a program that accepts a param (num) that will determine how many numbers will...
PYTHON- write a program that accepts a param (num) that will determine how many numbers will be in the output. every number after the first is the product of the prev 2 numbers, we will always start with [5,2] . return output (list) example. the user will insert 6 as the num. we start with [5,2] and the output will be [5,2,10,20,200,4000]
Write a Python program to ask how many elements do users want to create in a...
Write a Python program to ask how many elements do users want to create in a list, then let the user create 2 lists with the number of elements previously entered. Then create and display all combinations of letters, selecting each letter from a different key in a dictionary. Example: How many elements? 2 List 1 = ['a', 'b'] List 2 = ['c', 'd'] Output: ac ad bc bd
PYTHON SCRIPT Your parents pay you $3 for each trash bag full of leaves you take....
PYTHON SCRIPT Your parents pay you $3 for each trash bag full of leaves you take. If you can fill more than 10 bags in a month, they give you a bonus of $20. Write a program that asks the user how many bags of leaves they filled in the past month and prints out the total amount of money they made. For example, if someone fills 8 bags in a month, they would get $24. But, if they fill...
How do we know how many genes control development in an organism like Drosophila? And how...
How do we know how many genes control development in an organism like Drosophila? And how did we discover that selector genes specify which adult structures will be formed by body segments? Additionally, how do we know that eye formation in all animals is controlled by a binary switch gene?
Bash script Suppose you are working as a prof or TA and your students have an...
Bash script Suppose you are working as a prof or TA and your students have an assignment which requires them each to hand in exactly one file. You've got a directory with all of the submitted files in it, and no other files. You're also lucky enough to have a script that will do all the work of marking a submission; it will take the name of a submission file as its only parameter and will print out a single...
WRITE it in Python! how to Write a method named smallest largest that asks the user...
WRITE it in Python! how to Write a method named smallest largest that asks the user to enter numbers, then prints the smallest and largest of all the numbers typed in by the user. You may assume the user enters a valid number greater than 0 for the number of numbers to read. Here is an example dialogue: How many numbers do you want to enter? 4 Number 1: 5 Number 2: 11 Number 3: -2 Number 4: 3 Smallest...
how do you determine the size of a pipe?, a pipe to use from a pump...
how do you determine the size of a pipe?, a pipe to use from a pump to a boiler suction side and discharge side, if you want them to be equal, the pressure at the pump and at the boiler is equal? , if you know the volume flow rate and the pressure of both the pump and the boiler
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT