Here are some representative awk scripts which I use on my primary onsite Linux server (aka "Sleepy").
These are presented solely as examples for your reference, and completely without external comment.
-----
#! /bin/awk -f
#####
#
# verseData.awk
# MDJ 2022/03/30
#
# Reads the verseData.csv file
# (taken from the VerseData
# table of the VerseData
# MS Access Database on Doc)
# That table includes one
# line per KJV chapter.
#
# And outputs the verseList.csv
# file which includes one
# line per KJV verse.
#
# To Run:
# cd /media/mdavidjohnson/Elements/workingdir/Bible/verseData
# verseData.awk VerseData.csv
#
#####
# verseData input:
# $1 = ID = ID
# $2 = RNC = RunNumChapters
# $3 = BA = BookAbbrev
# $4 = CN = ChapterNum
# $5 = NV = NumVerses
# $6 = NPV = NumPrevVerses
# $7 = RNV = RunNumVerses
# verseList output:
# ID = ID (Uses RVN)
# RVN = RunVerseNum
# BA = BookAbbrev
# CN = ChapterNum
# VN = VerseNum
BEGIN {
# Specify the csv Field Delimiter
FS = ","
# Running Verse Number
RVN = 0
print " "
print "Start of verseData Expansion Run"
print " "
}
{
print $0
for(j=1; j<=$5; j++)
{
RVN = RVN + 1
RecordData = RVN "," RVN "," $3 "," $4 "," j
print "\t" RecordData
if (RVN == 1)
{
print RecordData > "/media/mdavidjohnson/Elements/workingdir/Bible/verseData/verseList.csv"
}
else
{
print RecordData >> "/media/mdavidjohnson/Elements/workingdir/Bible/verseData/verseList.csv"
}
}
}
END {
print " "
print "End of verseData Expansion Run"
print " "
}
#####
#
# EOF
#
#####
-----
#! /bin/awk -f
#####
#
# rp00.awk
# MDJ 2022/03/26
#
# Universal Version Step One:
# Read and Print All Lines.
# i.e. Check for gross syntax
# errors in the file identified
# on the command line.
#
# To Run:
# cdCoCo
# cd wk00
# rp00.awk filename
#
#####
{
print $0
}
#####
#
# EOF
#
#####
-----
#! /bin/awk -f
#####
#
# integ00.awk
# MDJ 2022/03/26
#
# Universal Version Step Two:
# Check the integrity of the
a file identified on the
# command line.
#
# To Run:
# cdCoCo
# cd wk00
# integ00.awk filename
#
#####
BEGIN {
BNn = 0 # Block Number Counter
BN = "00" # Block Number Counter Display
print " "
print "Beginning of Integrity Test"
print " "
}
{
# First Block
# First Line of Block
# = Question Number Comment Line
# Truncate $NF to remove trailing "\n"
NFT = substr($NF,1,2)
# Convert NFT string to numeric
NFn = 0 + NFT
# Convert BNn Counter to string
if ( BNn < 10 )
{
BN = "0" BNn
}
else
{
BN = "" BNn
}
if ( NFn == BNn )
{
print "Match " BN " " NFT
print $0
}
else
{
print "No Match " BN " " NFT " ERROR!"
print $0
exit 1
}
# Question Line
getline
print $0
# Correct Answer Line
getline
print $0
# Incorrect Answer #1 Line
getline
print $0
# Incorrect Answer #2 Line
getline
print $0
# Incorrect Answer #3 Line
getline
print $0
# Incorrect Answer #4 Line
getline
print $0
# Blank Line
getline
print $0
# Blocks 2 through last:
# Question Number Comment Line
while ( 1 == 1 )
{
r = getline
# If EOF:
if (r <= 0)
{
exit 0
}
else
{
BNn = BNn + 1
# Truncate $NF to remove trailing "\n"
NFT = substr($NF,1,2)
# Convert NFT string to numeric
NFn = 0 + NFT
# Convert BNn Counter to string
if ( BNn < 10 )
{
BN = "0" BNn
}
else
{
BN = "" BNn
}
if ( NFn == BNn )
{
print "Match " BN " " NFT
print $0
}
else
{
print "No Match " BN " " NFT " ERROR!"
print $0
exit 1
}
}
# Question Line
getline
print $0
# Correct Answer Line
getline
print $0
# Incorrect Answer #1 Line
getline
print $0
# Incorrect Answer #2 Line
getline
print $0
# Incorrect Answer #3 Line
getline
print $0
# Incorrect Answer #4 Line
getline
print $0
# Blank Line
getline
print $0
}
}
END {
print "End of Integrity Test"
print " "
}
#####
#
# EOF
#
#####
-----
#! /bin/awk -f
#####
#
# jsCopy00.awk
# MDJ 2022/03/26
#
# JavaScript Version Step Three:
# Copy the file identified
a on the command line to
# wk00/dataout; while also
# adding the Question Number
# Comment line.
#
# To Run:
# cdCoCo
# cd wk00
# pyCopy00.awk filename
#
#####
BEGIN {
BNn = 0 # Block Number Counter
BN = "00" # Block Number Counter Display
print " "
print "Beginning of Step Three Copy"
print " "
}
{
# First Block
# First Line of Block
# = Question Number Comment Line
# Truncate $NF to remove trailing "\n"
NFT = substr($NF,1,2)
# Convert NFT string to numeric
NFn = 0 + NFT
# Add closing semicolon to string
NFT = NFT ";"
$NF = NFT
# Convert BNn Counter to string
if ( BNn < 10 )
{
BN = "0" BNn "\;"
}
else
{
BN = "" BNn "\;"
}
if ( NFn == BNn )
{
print "Match " BN " " NFT
print $0
print $0 > "../wk00/dataout"
}
else
{
print "No Match " BN " " NFT " ERROR!"
print $0
exit 1
}
# Question Line
getline
print $0
print $0 >> "../wk00/dataout"
# Correct Answer Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #1 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #2 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #3 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #4 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Blank Line
getline
print $0
print $0 >> "../wk00/dataout"
# Blocks 2 through last:
# Question Number Comment Line
while ( 1 == 1 )
{
r = getline
# If EOF:
if (r <= 0)
{
exit 0
}
else
{
BNn = BNn + 1
# Truncate $NF to remove trailing "\n"
NFT = substr($NF,1,2)
# Convert NFT string to numeric
NFn = 0 + NFT
# Add closing semicolon to string
NFT = NFT ";"
$NF = NFT
# Convert BNn Counter to string
if ( BNn < 10 )
{
BN = "0" BNn "\;"
}
else
{
BN = "" BNn "\;"
}
if ( NFn == BNn )
{
print "Match " BN " " NFT
print $0
print $0 >> "../wk00/dataout"
}
else
{
print "No Match " BN " " NFT " ERROR!"
print $0
exit 1
}
}
# Question Line
getline
print $0
print $0 >> "../wk00/dataout"
# Correct Answer Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #1 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #2 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #3 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #4 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Blank Line
getline
print $0
print $0 >> "../wk00/dataout"
}
}
END {
print "End of Step Three Copy"
print " "
}
#####
#
# EOF
#
#####
-----
#! /bin/awk -f
#####
#
# pyCopy00.awk
# MDJ 2022/03/27
#
# Python Version Step Three:
# Copy the file identified
a on the command line to
# wk00/dataout; while also
# adding the Question Number
# Comment line.
#
# To Run:
# cdCoCo
# cd wk00
# pyCopy00.awk filename
#
#####
BEGIN {
BNn = 0 # Block Number Counter
BN = "00" # Block Number Counter Display
print " "
print "Beginning of Step Three Copy"
print " "
}
{
# First Block
# First Line of Block
# = Question Number Comment Line
# Replace the leading "//" with "#"
len = length($1)
t1 = substr($1,3,len)
$1 = "#" t1
# Truncate $NF to remove trailing "\n"
NFT = substr($NF,1,2)
# Convert NFT string to numeric
NFn = 0 + NFT
# Convert BNn Counter to string
if ( BNn < 10 )
{
BN = "0" BNn
}
else
{
BN = "" BNn
}
if ( NFn == BNn )
{
print "Match " BN " " NFT
print $0
print $0 > "../wk00/dataout"
}
else
{
print "No Match " BN " " NFT " ERROR!"
print $0
exit 1
}
# Question Line
getline
print $0
print $0 >> "../wk00/dataout"
# Correct Answer Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #1 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #2 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #3 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #4 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Blank Line
getline
print $0
print $0 >> "../wk00/dataout"
# Blocks 2 through last:
# Question Number Comment Line
while ( 1 == 1 )
{
r = getline
# If EOF:
if (r <= 0)
{
exit 0
}
else
{
BNn = BNn + 1
# Replace the leading "//" with "#"
len = length($1)
t1 = substr($1,3,len)
$1 = "#" t1
# Truncate $NF to remove trailing "\n"
NFT = substr($NF,1,2)
# Convert NFT string to numeric
NFn = 0 + NFT
# Convert BNn Counter to string
if ( BNn < 10 )
{
BN = "0" BNn
}
else
{
BN = "" BNn
}
if ( NFn == BNn )
{
print "Match " BN " " NFT
print $0
print $0 >> "../wk00/dataout"
}
else
{
print "No Match " BN " " NFT " ERROR!"
print $0
exit 1
}
}
# Question Line
getline
print $0
print $0 >> "../wk00/dataout"
# Correct Answer Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #1 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #2 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #3 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Incorrect Answer #4 Line
getline
print $0
print $0 >> "../wk00/dataout"
# Blank Line
getline
print $0
print $0 >> "../wk00/dataout"
}
}
END {
print "End of Step Three Copy"
print " "
}
#####
#
# EOF
#
#####
-----