Intro to Applied Cybersec
Lecture Notes
Assignments

Lecture 03: Regex, Text Editors, Bash, and awk

Notes

Regex

Slides from last lecture: regex.pdf

Regex101: https://regex101.com/

Text Editors

Bash utilities

References for input/output redirection on The Linux Documentation Project page.

If you’re curious about /dev/random/ vs /dev/urandom, this Stack Exchange post is a good read.

awk

The man pages coveres all syntax. Here are the most important bits:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
SYNOPSIS
       awk [ -F fs ] [ -v var=value ] [ 'prog' | -f progfile ] [ file ...  ]

An input line is normally made up of fields separated by white space, or by the regular expression FS.  
The fields are denoted $1, $2, ..., while $0 refers to the entire line.  
If FS is null, the input line is split into one field per character.

A pattern-action statement has the form:
       pattern { action }
A missing { action } means print the line; a missing pattern always matches.  
Pattern-action statements are separated by newlines or semicolons.

The special patterns BEGIN and END may be used to capture control before the first input line is read and after the last.  
BEGIN and END do not combine with other patterns.  
They may appear multiple times in a program and execute in the order they are read by awk.
Variable names with special meanings:
       FS   regular expression used to separate fields; also settable by option -Ffs.
       NF   number of fields in the current record.
       NR   ordinal number of the current record.

EXAMPLES
       length($0) > 72
       Print lines longer than 72 characters.
       { print $2, $1 }
       Print first two fields in opposite order.

       BEGIN     {    # Simulate echo(1)
            for (i = 1; i < ARGC; i++) printf "%s ", ARGV[i]
            printf "\n"
            exit }

perl

I suggest reading perldoc perlintro in full

Others

I’ve included a reference list of commands at the end of this article. This is not exhaustive (of course), but rather the commands that I think are most commonly used and that you might find helpful in your day-to-day operations.

Recording

Please note that only audio was recorded for this lecture.

Reference commands