Please post command output Assignment 3 Text File Utilities
/*Please post command +output*/
Assignment 3: Text File Utilities
The purpose of this lab is to become familiar using Unix\'s utilities for manipulating text files.
As a preliminary to this project make sure you have a copy of famous.dat. Be sure to submit each command as well as the results of each command.
Task A: 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
/*Please post command +output*/
Solution
Task A
$ find -maxdepth 1 -type f | wc -l
134
Task B
$ awk \'/ / {print $7}\' famous.dat | sort | uniq|wc -l
33
Task C
$ tail -n 8 famous.dat | awk -F \" \" \'{ print toupper($3)\" \"toupper($4)}\' | sort
DARWIN CHARLES
EINSTEIN ALBERT
GALILEO GALILELI
GOLDMAN EMMA
LOVELACE ADA
MANDELA NELSON
PARKS ROSA
RUSSELL BERTRAND
Task D
$ awk \'/ / { print $3\" \"$4\" \"$7}\' famous.dat | sort -k3 -k1 | head -n 15
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
$ date | awk -F \" \" \'{print tolower($1)}\'
wed

