Course outline
Course / The terminal and the language

Pull a column and change its case

Lab

How to fetch and submit this lab

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each lab: download it, edit the file named in the instructions, then submit.

gonomicon fetch week-1/03-02-cut-and-tr-column-case
cd 03-02-cut-and-tr-column-case
gonomicon submit

Go installed? gonomicon test runs the visible test on your computer first. Submitting also runs hidden checks on our server.

Goal

The file testdata/people.csv is comma-separated. Print the first field of every line, uppercased, one per line.

Example

If testdata/people.csv held:

dana,28,seattle
erin,33,boston

your script prints:

DANA
ERIN

One line of output per line of input, in the same order. If a line's first field is empty, print an empty line.

Rules

  • Edit answer.sh. Read testdata/people.csv; do not hard-code the names.
  • The separator is a comma. Field 1 is the first field, counting from 1. Every line has at least one comma.
  • Uppercase the output, whatever case the names are in.
  • Print no header and no extra lines.

What you'll practice

cut -d ... -f 1, tr 'a-z' 'A-Z', and piping one command into another.

Run it

gonomicon fetch week-1/03-02-cut-and-tr-column-case
cd 03-02-cut-and-tr-column-case
gonomicon test
gonomicon submit

Hints

  1. cut -d "," -f 1 keeps the first comma-separated field of every line.
  2. tr 'a-z' 'A-Z' turns each lowercase letter into uppercase.
  3. Pipe the two together: cut -d "," -f 1 testdata/people.csv | tr 'a-z' 'A-Z'.

Something wrong with this lesson? Report a problem