1. Create a UNIX command line that shows the count of the number of people in ph
ID: 3709547 • Letter: 1
Question
1. Create a UNIX command line that shows the count of the number of people in phones.dat with a phone number in the 757 area code. Based on the sample phoneList.dat file, your output should be: 3 Note that you can't just echo the number shown in the sample phones.dat file like this: $ echo "3" 3 This echo would not work correctly for any data file of this same format. Another data file of the same format but with different contents might have 8,500 phone numbers in the 757 area code; another file might have 0. Figure out a command line that will come up with the right count for the number of phone numbers in the area code 757 no matter the contents of phones.dat. (You can assume that the file name is phoneList.dat and that you are searching for the 757 area code when you make your command line.) Hint: you can use piping and grep command to get this done.Explanation / Answer
Explanation:
matching for the code 757 in the phones.dat file the matching records are passed throught the pipe and the count of matching records are found with wc command.
Commands Explanation:
grep stands for global regular expression printer.
It searches for a given patern in a file.
grep -[options] [pattern] [filename]
few options grep holds are as follows
-c counts the total no of files containing the pattern
-v display the lines not containing the pattern
-n display the line with line number
-l display the filenames containing the pattern
-o displays only the part of the string which matchced the search pattern
Pipes are used to provied flow of data by which different commands get chained up.
Pipe is represented using | symbol.
wc command gives the word count
wc -[options] [filename]
few options wc holds are as follows
c -- prints the bytes count
l -- prints the new line count
w -- prints the word count
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.