More command line

Created Tuesday 16 February 2021

First, the granddaddies:


SED and AWK

You can do A LOT with these, they're basically languages in their own right. They're a little difficult, especially AWK.

SED

REGULAR EXPRESSIONS

echo “Good day” | sed 's/day/night/'
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/sed1line.txt


AWK

awk <search pattern> {<program actions>}
Also a text-processor, good for flat-file databases
Also, an entire language

awk ' /apples/ { print $2 “ “ $1 } '

but, some of my go to stuff


tr

Transliterate, i.e.
CHANGE a character to another

tr [a-z] [A-Z]

cut

cut a string according to, e.g. fields

(this is my favorite. I just find it way more intuitive than awk/sed)

-f = which field or fields and optionally
-d = change the delimiter

e.g. to get the last name:

cut -f2 -d " "
-> ...combine with the following

wc

Is for "word count" — but it can do newline and byte counts.

Since bash can do a lot of "by line" stuff, wc -l
might be valuable

(again, a lot of these tools have "count" built in, but I find this easy to remember)

FILE

hey, it's a command. Can tell you about a file



Process file line by line: