Frontier Software

Core Utilities

Manual

List of Commands

grep

grep me no patterns and I’ll tell you no lines. — fortune cooky manual wikibooks As explained in The Unix Programing Environment by Brian Kernighan and Rob Pike, sed can do just about everything grep can. sed -n '/pattern/p' files is the same as grep -h pattern files Why do we have both sed and grep? After all, grep is just a simple special case of sed. Part of the reason is history — grep came well before sed.

sed

Manual Four types of sed scripts 1. Multiple Edits to the Same File 2. Making Changes Across a Set of Files 3. Extracting Contents of a File 4. Edits To Go Substitute [address]s/regexp/replacement/[flags] The ‘s’ command (as in substitute) is probably the most important in ‘sed’ and has a lot of different options. The syntax of the ‘s’ command is ’s/REGEXP/REPLACEMENT/FLAGS'. The ‘/’ characters may be uniformly replaced by any other single character within any given ‘s’ command.

awk

Manual print #!/usr/bin/bash awk '{ print }' "$@" BEGIN #!/usr/bin/bash awk 'BEGIN { print "NAME\tRATE\tHOURS"; print "" } { print }' "$@" END #!/usr/bin/bash awk ' { OFS="\t" } BEGIN { print "NAME", "RATE", "HOURS"; print "" } { print $1, $2, $3} { rate = rate + $2 } { hours = hours + $3 } END { print "AVERAGE", rate / NR, hours / NR }' "$@" #!/usr/bin/bash ExampleGroup 'basic awk oneliner' Example 'print emp.

date

The primary reason I’m using bash rather than some programing language is to get easy access to GNU’s powerful date program. It automagically reads most text descriptions of dates and can then translate them to what I want, which is ISO 8601 as specified by schema.org. Getting dates right has been a constant source of bugs — it took me a while to figure that because my development machine is set to my local time, “Africa/Johannesburg” and my server to “UTC”, joeblog.