theoboldalex / standup_comedy

"It is called standup because your code is a joke" and other one-liners

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Standup Comedy

"It is called standup because your code is a joke" and other one-liners.

-- Me

Quickstart

Clone the repo

git clone https://github.com/theoboldalex/standup_comedy.git

Inspect the data

wc -l worker_bees.csv

head -n 1 worker_bees.csv

cat worker_bees.csv

Work through the exercises

There are a number of exercises listed below. Solve them in any way you see fit. There is no wrong or right way to do this. Just use the tools you are most comfortable with, practice and pick up some new tools, tips and utilities along the way.

Warning

If you accidentally (or purposefully) bork your input file, simply generate a new one by running make.

Exercises

Note

From here on out we will refer to worker_bees.csv the "input file".

Print the number of columns contained in the input file.

Expand Solution

awk

awk -F, '{print NF; exit}' worker_bees.csv

perl

perl -F, -lane 'print scalar @F; exit' worker_bees.csv

shell

head -n 1 worker_bees.csv | tr -dc ',\n' | wc -c

What is the higest salary of all worker bees?

Expand Solution

awk

awk -F, 'NR > 1 && $7 > max {max=$7} END{print max}' worker_bees.csv

What is the total yearly salary of the worker bees based in France?

Expand Solution

awk

awk -F, '$6 ~ /FR/ {ts+=$7} END{print ts}' worker_bees.csv

What is the job title of the oldest worker bee?

Expand Solution

awk && shell

awk -F, 'NR > 1 {print $4 " " $5}' worker_bees.csv | sort | head -n 1

Which country has the highest headcount?

Expand Solution

awk

awk -F, 'NR > 1 {ciso[$6]++} END{for (c in ciso){print c ": " ciso[c]}}' worker_bees.csv

Print the full name and job title of all worker bees that have fred in their name.

Important

Beware some worker bee names may not be all lower cased.

Expand Solution

awk

awk -F, '/[fF]red/ {print $1 " " $2 " " $5}' worker_bees.csv

What is the most common job title for a worker bee? Print a table of all job titles and the frequency with which they appear

Expand Solution

awk

awk -F, 'NR > 1 {titles[$5]++} END{for (t in titles) {print t ": " titles[t]}}' worker_bees.csv

How many lead developers are there working from the US?

Expand Solution

awk

awk -F, '/Lead Developer/ && $7 = "US" {c+=1} END{print c}' worker_bees.csv

Make a copy of the input file but convert the format from csv to tsv

Expand Solution

sed

sed 's/,/\t/g' worker_bees.csv > worker_bees.tsv

Make a new row of data right below the headers with your name and the job title Scrum Mainer

Expand Solution

awk

awk -F, 'NR == 1 {print; print "Alex,Theobold,alex.theobold@shitpost.ing,1987-06-30,\"Scrum Mainer\",UK,69420"} NR > 1' worker_bees.csv > tmp && mv tmp worker_bees.csv

About

"It is called standup because your code is a joke" and other one-liners


Languages

Language:PHP 98.2%Language:Makefile 1.8%