Related tools¶
Learning outcomes
- Hear about the tools similar to
awk
For teachers
Teaching goals are:
- Show the tools similar to
awk
Lesson plan:
- 5 mins: prior knowledge
- 5 mins: presentation
- ? mins: challenge
- 5 mins: feedback
Overview¶
In this session, we learn about the Linux tools related to awk.
flowchart TD
classDef focus_node fill:#fff,color:#000,stroke-width:4px
awk:::focus_node
cut
grep
sed
tr
wc
regexps[Regular expressions]
split_data_in_columns[Split data into columns]
count[Count]
replace[Replace]
%% Tools
awk --> |can do| regexps
sed --> |can do| regexps
grep --> |can do| regexps
awk --> |can do| split_data_in_columns
cut --> |can do| split_data_in_columns
awk --> |can do| count
wc --> |can do| count
awk --> |can do| replace
tr --> |can do| replace
sed --> |can do| replace
| Tool | Regular expressions | Split data into columns | Replace | Count |
|---|---|---|---|---|
awk |
Yes | Yes | Yes | Yes |
cut |
No | Yes | No | No |
grep |
Yes | No | No | Yes |
sed |
Yes | Yes | Yes | Yes |
tr |
No | No | Yes | No |
wc |
No | No | No | Yes |
An overview what tools can do by themselves.
Note that most tools are not intended to do all by themselves. Instead, they are intended to do one thing well and be part of pipelines.
Exercises¶
Exercise 1: cut¶
Learning outcomes
- Use
cut
Read:
In a terminal, do:
to download a file called diamonds_raw.csv.
Then, in a terminal, do:
man cutcut -d "," -f 2 diamonds_raw.csvcat diamonds_raw.csv | cut -d "," -f 2
Express in your own words: what does cut do?
Exercise 2: grep¶
Learning outcomes
- Use
grep
Read:
In a terminal, do:
to download a file called satellites.csv.
Then, in a terminal, do:
man cutgrep om satellites.csvcat satellites.csv | grep [^aeiou]om
Express in your own words: what does grep do?
Exercise 3: sed¶
Learning outcomes
- Use
sed
Read:
In a terminal, do:
to download a file called pg1787.txt.
Then, in a terminal, do:
man sedsed 's/Hamlet/Frederik X/g' pg1787.txtsed 's/Hamlet/Frederik X/g' pg1787.txt | awk '/Frederik X/'sed 's/Hamlet/Frederik X/' pg1787.txt | awk '/Frederik X/'
Express in your own words: what does sed do?
Exercise 4: tr¶
Learning outcomes
- Use
tr
Read:
Then, in a terminal, do:
man trecho "Hello" | tr -s e aecho "Hello" | tr -d eecho "Hello world" | tr -d aeiou
Express in your own words: what does tr do?
Exercise 5: wc¶
Learning outcomes
- Use
wc
Read:
In a terminal, do:
to download a file called pg1787.txt.
Then, in a terminal, do:
man sedwc pg1787.txtwc pg1787.txt --lineswc pg1787.txt --wordsawk '/Hamlet/' pg1787.txt | wc --lines
Express in your own words: what does wc do?