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
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....
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...
Wal-Mart Online Wal-Mart is one of the largest companies in America. It is definitely the largest...
Wal-Mart Online Wal-Mart is one of the largest companies in America. It is definitely the largest retailer, both in terms of the number of stores (8,970 worldwide in 2011) and the level of sales ($419 billion from the 2011 Annual Report). By pushing suppliers to continually reduce costs, Wal-Mart is known for pursuing low prices and the stores often attract customers solely in-terested in lower prices. With Wal-Mart’s expansion into groceries, the company has be-come the largest retail grocer in...
What tools could AA leaders have used to increase their awareness of internal and external issues?...
What tools could AA leaders have used to increase their awareness of internal and external issues? ???ALASKA AIRLINES: NAVIGATING CHANGE In the autumn of 2007, Alaska Airlines executives adjourned at the end of a long and stressful day in the midst of a multi-day strategic planning session. Most headed outside to relax, unwind and enjoy a bonfire on the shore of Semiahmoo Spit, outside the meeting venue in Blaine, a seaport town in northwest Washington state. Meanwhile, several members of...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...