Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make a one-line Unix command - using pipe(s) - to display the number of files in

ID: 3907824 • Letter: M

Question

Make a one-line Unix command - using pipe(s) - to display the number of files in your home directory including the hidden files that begin with '.' Note: Output will be the number of files you have in your directory

Task B: Make a one-line Unix command - using pipe(s) - to display the number of unique zip codes in famous.dat (hint: use -u on sort).

Note: Output will be the number: 33

Task C: Using the fixed length field file called famous.dat, make a one-line Unix command - using pipe(s) - to display an alphabetical list of the last and first names in upper case of the last 8 people in the file.

Hint: Names are in columns 6 through 35.

Output is this..

DARWIN CHARLES

EINSTEIN ALBERT

GALILEO GALILELI

GOLDMAN EMMA

LOVELACE ADA

MANDELA NELSON

PARKS ROSA

RUSSELL BERTRAND

Task D: Using the fixed length field file called famous.dat, make a one-line Unix command - using pipe(s) - to display a list of last name, first name and zip only. Sort first on the zip code, then on last name when there are duplicate zip codes. To save on amount of output produced, just display the first 15 lines of the output from the above, as the last command in the pipe. Hint: zip codes are in columns 44 through 48.

Note: Here is what the output should look like:

moose bullwinkle 94111

franti michael 94112

marley bob 94112

richards keith 94112

simone nina 94112

einstein albert 94113

russell bertrand 94113

oliver mary 94114

hanh thichNhat 94115

kropotkin peter 94115

chomsky noam 94116

squirrel rocketJ 94122

chapman tracy 94211

marley rita 94212

black mary 94221

Task E: Write a one-line Unix command using pipes, to display just the current day of the week in lower case (i.e. mon). Hint: Cut the first part of the date command then pipe to tr. Note: Example for output would be wed if I run the command on a Wednesday

famous.dat file

01 m motzart amadeous 25 2nd 94233

02 m guthrie woody 23 2nd 94223

03 f simone nina 27 2nd 94112

04 m lennon john 29 2nd 94221

05 f harris emmylou 20 2nd 94222

06 m marley bob 22 2nd 94112

07 f marley rita 26 2nd 94212

08 f warwick dione 26 2nd 94222

09 m prine john 35 3rd 94321

10 m franti michael 34 3rd 94112

11 f black mary 21 2nd 94221

12 m dylan bob 37 3rd 94311

13 f baez joan 36 3rd 94311

14 m richards keith 42 4th 94112

15 m jagger mick 41 4th 95115

16 m mcdonald countryjoe 46 4th 94543

17 f chapman tracy 43 4th 94211

18 m springstein bruce 45 4th 94323

19 f mitchell joni 40 4th 94444

20 f walker alice 37 3rd 94332

21 f oliver mary 47 4th 94114

22 m kotzwinkle william 44 4th 94433

23 f kate wilhelm 73 7th 94778

24 m heinlein robert 74 7th 94765

25 m asimov isaac 75 7th 94777

26 m moose bullwinkle 16 1st 94111

27 m squirrel rocketJ 17 1st 94122

28 f fenwich nell 13 1st 94221

29 m peobody mr 18 1st 94222

30 m longlastname longfirstname 11 1st 94313

31 m leaves t 22 2nd 94223

32 m hanh thichNhat 26 2nd 94115

33 m chomsky noam 34 3rd 94116

34 m morrison norman 71 7th 94771

35 f anthony susanB 48 4th 94321

36 m kropotkin peter 49 4th 94115

37 m gandhi mohatmas 53 5th 95123

38 f tubman harriet 50 5th 95555

39 m king martinLuther 52 5th 95112

40 m chavez cesar 57 5th 95112

41 m douglas frederick 66 6th 94666

42 f goldman emma 64 6th 94611

43 f mandela nelson 60 6th 96543

44 f parks rosa 72 7th 94777

45 m russell bertrand 55 5th 94113

46 f lovelace ada 56 5th 95123

47 m darwin charles 59 5th 95123

48 m galileo galileli 58 5th 95113

49 m einstein albert 54 5th 94113

Explanation / Answer

Solution:

a) ls -la /home | grep ^- | wc -l

here, ls -la will give all files including hidden ones, then we are using grep command only to search the files using “^-“ and the output is passed to wc -l to get the word count.

b) cat famous.dat | cut -d “ “ -f 7 | sort -u | wc -l

using cat command we are viewing the file which is being used by cut command to find only the zip codes and then it is being passed through sort -u to get the unique codes and wc -l is used to get the number of zip codes.

c) cat famous.dat | cut -d " " -f 3,4 | tr [a-z] [A-Z] | tail -n 8

here using cat to view as file and using cut to get the 3rd and 4th column after that the output is used in tr command to change small letter to capital letters and tail command is used to display last 8 people

d) awk -F " " '{print $7, $3, $4}' famous.dat | sort -V | awk -F " " '{print $2, $3, $1}' | head -n 15

here awk command is used to get 7th , 3rd and 4th column of famous.dat file. Then we are sorting the zip codes using version sorting and then again rearranging it with awk command. And then using head command we get the first 15 results.

e) date | cut -d " " -f 1 | tr [A-Z] [a-z]

Here output of date command is passed through cut command to get the 1st column and then it is being changed to small letter using tr command

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote