Question

In linux: Perl scripts What would be the search pattern for extracting all the lines that...

In linux:

Perl scripts

What would be the search pattern for extracting all the lines that contain at least a 3-digit number in /etc/services, such as the lines that have 110 (pop3) or 143 (imap), but not the lines that contain 1649 (kermit), 3306 (mysql), or 10080 (amanda), etc.

Homework Answers

Answer #1

#!/usr/bin/perl

use strict;

my $filename = '/etc/services';

# opening file to read

open my $info, $filename or die "Could not open $filename: $!";

# reading line by line

while( my $line = <$info>)  {   

    if ($line =~ /#/){}

    else{

    # splitting by space to find 2nd col

    my $v =  ((split ' ', $line)[1]);  

    # splitting by / to find process id

    my $proceess_id = ((split '/', $v)[0]);

    # if length 3 then printing it

    if (length($proceess_id)==3){

        print $line;

    }

    }

}

# OUT

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
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective...
Chapter 8: Searching, Extracting, and Archiving Data Exercise 8.a: Using grep, find, and regular expressions (Objective 3.2) Linux Distribution: Fedora (non-root user & password needed) Desktop Environment: GNOME 3 1.   If you have not already done so, boot up your computer (or virtual machine) to start the Fedora Linux distribution. 2.   When the machine has booted up, access the tty2 virtual terminal by pressing Ctrl+Alt+F2. 3.   Log on to a regular user’s account by typing in the username at the...
What is the chance a randomly selected employee would get a non-zero bonus amount? What is...
What is the chance a randomly selected employee would get a non-zero bonus amount? What is the chance a randomly selected employee would get at least $6000? What is the expected bonus value of the bonus amounts? What are the variance and standard deviation of the bonus amount? Binomial Suppose according to past data for a small boutique, about 30% of the customers who walk into the store purchase at least one item. Today 10 individual customers walked into the...
Fancy Millwork has a factory that produces custom kitchen cabinets. It has multiple product lines. Materials...
Fancy Millwork has a factory that produces custom kitchen cabinets. It has multiple product lines. Materials and labor for the cabinets are determined by each job. To simplify the assignment, we will assume the following average costs. The company estimates that it will have 32,000 direct labor hours in total for the kitchen cabinets. The materials include $2,000 for the wood and other materials on a per job basis. It requires 40 hours of labor on average for a custom...
The ISO 9000 series of quality management systems standard has been widely applied all over the...
The ISO 9000 series of quality management systems standard has been widely applied all over the world since its introduction in 1987. By the end of 2013, ISO 9000 had been adopted by over 1,129,000 facilities in 189 countries. Both academics and practitioners are interested in understanding the relationship between adoption of ISO 9000, and other factors (Christmann & Taylor, 2006; Du, Yin, & Zhang, 2016; Fikru, 2014a, 2014b, 2016; Nakamura, Takahashi, & Vertinsky, 2001; Pekovic, 2010; Wu, Chu, &...
Develop a 2018 individual tax return (with all required forms and supporting schedules) for Rob and...
Develop a 2018 individual tax return (with all required forms and supporting schedules) for Rob and Laura Petrie that is both professional in appearance and technically correct. The use of tax software or a professional tax preparer to complete this project is prohibited. You can access fill-in forms (in pdf format) on the IRS website (www.irs.gov) by clicking on “More” on the left side of the homepage in the “Forms and Pubs” section. Next, click on the “Current Forms and...
CASA3: Draft Problem Statement for Report with Preliminary Scholarly Sources List CASA3 has 2 parts but...
CASA3: Draft Problem Statement for Report with Preliminary Scholarly Sources List CASA3 has 2 parts but is to be submitted as one document. Part A: Draft problem statement for report Part B: Preliminary scholarly sources list Here are some points to consider: Part A:. Management Problem Statement: Revisit, improve and enhance your CASA1- Management Problem Statement Link to the Functions of Management (planning, leading, organising and controlling) Clearly indicate a management problem or potential problem Balance of facts from the...
1. For a pair of sample x- and y-values, what is the difference between the observed...
1. For a pair of sample x- and y-values, what is the difference between the observed value of y and the predicted value of y? a) An outlier b) The explanatory variable c) A residual d) The response variable 2. Which of the following statements is false: a) The correlation coefficient is unitless. b) A correlation coefficient of 0.62 suggests a stronger correlation than a correlation coefficient of -0.82. c) The correlation coefficient, r, is always between -1 and 1....
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
INTELLECTUAL PROPERTY  Industrial property forms part of the broader concept of "intellectual property."  The...
INTELLECTUAL PROPERTY  Industrial property forms part of the broader concept of "intellectual property."  The objects of intellectual property are the creations of the human mind, the human intellect hence the expression "intellectual" property.  In a somewhat simplified way, one can state that intellectual property relates to pieces of information which can be incorporated in tangible objects at the same time in an unlimited number of copies at different locations anywhere in the world.  The property is...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most...
      MK Restaurant: Branding of Thai-Style Hotpot The restaurant industry is one of the most competitive in Thailand. With a large number of players ranging from restaurants in five-star hotels, global fast-food chains to small stalls along the streets and everything in between, the Thais are spoiled for choice. In addition, as the world becomes globalized, consumers are familiar with international dishes and would not hesitate to try new offerings from the other side of the globe. As a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT