Frontier Software

Core Utilities

Manual

List of Commands

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.

grep

manual wikibooks #!/bin/bash # dictionary_matches $dictionary $text function json_dict_words { arr=() while IFS= read -r line; do arr+=("$line") done <<< "$(grep -Fwio -f "${HOME}/share/dict/${1}" <<< "$2" | sort -u)" if [[ -n ${arr[*]} ]]; then jq -cn '$ARGS.positional' --args "${arr[@]}" fi } ExampleGroup 'Create a JSON array of phrases matching those in a dictionary' Example 'find a word in the text' When call json_dict_words 'actors' 'Appel @ Padstal' The output should equal '["Appel"]' The status should be success The error should be blank End Example 'find a phrase in the text' When call json_dict_words 'actors' 'n Aand saam Jakkie Louw (ten bate van SAACA) @ Die Centurion Teater' The output should equal '["Jakkie Louw"]' The status should be success The error should be blank End Example 'find two phrases in the text' When call json_dict_words 'actors' 'Emile Alexander & Dakes LIVE in Johannesburg at Gatzbys LIVE, Midrand - 10 February 2024' The output should equal '["Dakes","Emile Alexander"]' The status should be success The error should be blank End Example 'no matches' When call json_dict_words 'actors' 'Nothing in dictionary' The output should equal '' The status should be success The error should be blank End End As is common, the above uses IFS= read -r and courtesy of the SC2162 I discovered IFS= clears the internal field separator prevents stripping leand and trailing whitepace, which I actuall usually want.

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.

sed

Manual Delete lines ‘/REGEXP/d’ Create a newline after each newline as needed by md sed G Insert lines ‘a TEXT’ $ seq 3 | sed '2a hello' Transliterate ‘y/SOURCE-CHARS/DEST-CHARS/’ Transliterate any characters in the pattern space which match any of the SOURCE-CHARS with the corresponding character in DEST-CHARS. See the ‘tr’ command from GNU coreutils for similar functionality. Print (as in grep) ‘/REGEXP/p’ Range addresses To extract YAML between lines starting and ending with — in Hugo index.