Zip codes

From 22126
Revision as of 16:23, 19 March 2024 by WikiSysop (talk | contribs) (Created page with " <H2>Extra fun with US zip codes</H2> <p>If you are 100% done with everything, you can have fun with the following exercise involving [https://en.wikipedia.org/wiki/ZIP_Code US zip codes]. This is mostly for people with previous Unix experience. </p> You will find the following file: <pre> /home/projects/22126_NGS/exercises/unix/ZIP_CODES.csv.gz </pre> No need to copy it or unzip it. You can view it with '''zcat''' or '''zless'''. csv stands for comma-separated val...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Extra fun with US zip codes

If you are 100% done with everything, you can have fun with the following exercise involving US zip codes. This is mostly for people with previous Unix experience.

You will find the following file:

/home/projects/22126_NGS/exercises/unix/ZIP_CODES.csv.gz


No need to copy it or unzip it. You can view it with zcat or zless.

csv stands for comma-separated values i.e. column1,column2,...

Some very useful commands:

  1. cat or in our case zcat
  2. head
  3. tail
  4. awk
  5. sed
  6. sort
  7. uniq
  8. wc
  9. grep

For csv files, to get the first column, I recommend either:

zcat /home/projects/22126_NGS/exercises/unix/ZIP_CODES.csv.gz | cut -d , -f 1
zcat /home/projects/22126_NGS/exercises/unix/ZIP_CODES.csv.gz |  awk 'BEGIN{FS=","}{put code here}'

Q1: How many zip codes are in New York State ( STATE = NY)


Q2: Among the zip codes in New York State from Q1, what are the top 3 cities with the most ZIP codes assigned to them?


Q3: Among the zip codes in New York State from Q1, how many cities have a single ZIP code assigned to them?


Q4: Among the zip codes in New York State from Q1, count how many cities have 1 ZIP code assigned to them, how many have 2 ZIP codes, how many have 3 ZIP codes, .... etc


Q5: How many zip codes are below the famous Mason-Dixon Line (Latitude < 39.4)


Q6: For each different US state, list the city with the most zip codes assigned to it.


Q7: How many cities in the file begin with the letter 'M' ?



Please find the answers here

Congratulations you finished the exercise!