Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#######
#
# E-scripts on awk.
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
# An introduction to eev can be found here:
#
#   (find-eev-quick-intro)
#   http://angg.twu.net/eev-intros/find-eev-quick-intro.html
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/e/awk.e>
#           or at <http://angg.twu.net/e/awk.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######




# «.changer.awk»	(to "changer.awk")
# «.ARGV»		(to "ARGV")
# «.ARGC»		(to "ARGC")
# «.NR-and-NF»		(to "NR-and-NF")
# «.printf»		(to "printf")
# «.figlet»		(to "figlet")
# «.getline»		(to "getline")
# «.gawk-docs»		(to "gawk-docs")
# «.awkbookcode»	(to "awkbookcode")
# «.recursive-descent»	(to "recursive-descent")
# «.getting-started»	(to "getting-started")
# «.sub»		(to "sub")
# «.txr»		(to "txr")



# (find-status   "gawk-doc")
# (find-vldifile "gawk-doc.list")
# (find-udfile   "gawk-doc/")

# (find-status "gawk")
# (find-vldifile "gawk.list")
# (find-fline "/usr/doc/gawk/")
# (find-fline "/usr/share/awk/")
# (find-fline "/usr/doc/gawk/examples/data/")
# (find-fline "/usr/doc/gawk/examples/misc/")
# (find-fline "/usr/doc/gawk/examples/network/")
# (find-fline "/usr/doc/gawk/examples/prog/")
# (find-fline "/usr/bin/igawk")
# (find-man "1 gawk")
# (find-man "1 gawk" "Built-in Variables")
# (find-man "1 gawk" "I/O Statements")
# (find-man "1 gawk" "String Functions")

# (find-node "(gawk)Top")
# (find-node "(gawkinet)Top")
# (find-node "(gawk)Getline/Variable")



# (find-status "mawk")
# (find-vldifile "mawk.list")
# (find-fline "/usr/doc/mawk/")
# (find-fline "/usr/doc/mawk/examples/")
# (find-fline "/usr/doc/mawk/examples/deps.awk.gz")
# (find-man "1 mawk")

#*
rm -Rv ~/tmp/awktest/
mkdir  ~/tmp/awktest/
cd     ~/tmp/awktest/

cat > file1 <<'---'
aaa
@beg
  bbb
  ccc
@end
ddd
---

cat > file2 <<'---'
    xxxx
    yyyy
---

#*
# (find-node "(gawk)Running gawk")
# (find-node "(gawk)Action Overview")
cd ~/tmp/awktest/
awk '
  /@beg/ { print "BEG!" }
  /@end/ { print "END!" }
  //
' file1

awk '
  /@beg/ { print "BEG!" }
  /@end/ { print "END!" }
  { print }
' file1

# (find-node "(gawk)Next Statement")
awk '
  /@beg/ { print "BEG!"; next }
  /@end/ { print "END!"; next }
  { print }
' file1

#*
cd ~/tmp/awktest/
awk '
  /@beg/ { print "BEG!"; omit = 1; next }
  /@end/ { print "END!"; omit = 0; next }
  ! omit { print }
' file1

#*
# (find-node "(gawk)Getline/Variable/File")
# (find-node "(gawk)Options" "`--posix'")
# (find-node "(gawk)Options" "`--traditional'")
cd ~/tmp/awktest/
awk '
  /@beg/ { print "BEG!"; omit = 1;
           while (getline line < "file2") print line;
           next
         }
  /@end/ { print "END!"; omit = 0; next }
  ! omit { print }
' file1

#*





#####
#
# changer.awk
# 2002may04
#
#####

# «changer.awk»  (to ".changer.awk")
#*
rm -Rv ~/tmp/awktest/
mkdir  ~/tmp/awktest/
cd     ~/tmp/awktest/
cp -v ~/eev/changer.awk .

# (find-eev "changer.awk")
# (find-eev "rcfiles/.bashrc")

cat > .bashrc <<'---'
aaa
@beg
  bbb
  ccc
@end
ddd
---
awk -v eevblock=$HOME/eev/rcfiles/.bashrc	\
    -f changer.awk				\
       .bashrc

cat > .bashrc <<'---'
aaa
# Beginning of the eev block:
blablabla.
# End of the eev block.
ddd
---
awk -v eevblock=$HOME/eev/rcfiles/.bashrc	\
    -f changer.awk				\
       .bashrc

#*

# (find-node "(gawk)Index")



#*
rm -Rv ~/tmp/awktest/
mkdir  ~/tmp/awktest/
cd     ~/tmp/awktest/
cp -v ~/.bashrc ~/.emacs ~/.zshrc ~/.gdbinit .

# (find-eev "changer.sh")
# (find-eev "changer.awk")
cd ~/eev/
# ./changer.sh rcfiles/.bashrc \
#   ~/tmp/awktest/.bashrc ~/tmp/awktest/.bashrc_pre-eev
# ./changer.sh rcfiles/.bashrc \
#   ~/tmp/awktest/.bashrc ~/tmp/awktest/.bashrc_pre-eev
 
./changer.sh rcfiles/.emacs   ~/tmp/awktest/.emacs
./changer.sh rcfiles/.bashrc  ~/tmp/awktest/.bashrc
./changer.sh rcfiles/.zshrc   ~/tmp/awktest/.zshrc
./changer.sh rcfiles/.gdbinit ~/tmp/awktest/.gdbinit
./changer.sh rcfiles/.cshrc   ~/tmp/awktest/.cshrc

# ~/tmp/awktest/.gdbinit_pre-eev

cd     ~/tmp/awktest/

#*
# (find-fline "~/tmp/awktest/")




####
#
# argv
# 2004mar18
#
####

# «ARGV»  (to ".ARGV")
# «ARGC»  (to ".ARGC")
# (find-gawknode "")
# (find-gawknode "Auto-set" "`ARGC, ARGV'")
# (find-gawknode "Auto-set" "ENVIRON")
# (find-gawknode "Other Arguments")
# (find-gawknode "Auto-set" "`ARGIND #'")
#*
awk 'BEGIN { for (i=0; i<ARGC; i++) print i, ARGV[i] }' arg1 arg2

#*
unset FOO;    gawk 'BEGIN { print ENVIRON["FOO"] }'
FOO=bar       gawk 'BEGIN { print ENVIRON["FOO"] }'
FOO="baz baz" gawk 'BEGIN { print ENVIRON["FOO"] }'

#*
rm -Rv /tmp/awk/
mkdir  /tmp/awk/
cd     /tmp/awk/

echo FOO > foo
echo BAR > bar

awk ' BEGIN { for(i=0;i<ARGC;i++) print i,ARGV[i] }
      { print }
  ' foo bar 

echo input from stdin | \
awk ' BEGIN { for(i=0;i<ARGC;i++) print i,ARGV[i]; ARGC=1 }
      { print }
  ' foo bar

#*




#####
#
# NR-and-NF
# 2021oct12
#
#####

# «NR-and-NF»  (to ".NR-and-NF")
# (find-gawknode "Auto-set" "'NR'" "number of input records 'awk' has processed")
# (find-gawknode "Auto-set" "'NF'" "The number of fields in the current")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
ghc --version
ghc --version | awk '{print NF}'
ghc --version | awk '{print $NF}'
echo a/bb/ccc/ddd | awk -F/ '{print $NF}'



#####
#
# printf
# 2021oct12
#
#####

# «printf»  (to ".printf")
# (find-gawknode "Basic Printf")




#####
#
# figlet
# 2021dec17
#
#####

# «figlet»  (to ".figlet")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
echo 'Foo bar' | figlet -f standard | awk '{printf "-- %s\n", $0}'




#####
#
# getline
# 2004oct13
#
#####

# «getline»  (to ".getline")
# (find-node "(gawk)Plain Getline")
# (find-node "(gawk)Getline/Variable/File")
#*
rm -Rv /tmp/awk/
mkdir  /tmp/awk/
cd     /tmp/awk/
cat > myfile <<'%%%'
one
two two

four four four four
%%%

awk 'BEGIN {
  do {
    a = (getline line < "myfile")
    print a, line
  } while (a)
}'

awk 'BEGIN {
  while (getline line < "myfile")
    print line
  print "last line:", line
}'

rm myfile
awk 'BEGIN {
  getline first_line < "myfile"
  while (getline last_line < "myfile") {}
  print "first line:", first_line
  print "last line: ", last_line
}'
#*




#####
#
# gawk docs (on etch)
# 2007may18
#
#####

# «gawk-docs»  (to ".gawk-docs")
# http://www.gnu.org/
# http://www.gnu.org/software/gawk/gawk.html
# http://ftp.gnu.org/gnu/gawk/gawk-3.1.5.tar.bz2
#*
rm -Rv ~/usrc/gawk-3.1.5/
tar -C ~/usrc/ -xvjf \
  $S/http/ftp.gnu.org/gnu/gawk/gawk-3.1.5.tar.bz2
cd     ~/usrc/gawk-3.1.5/

#*
# (code-c-d "gawk" "~/usrc/gawk-3.1.5/" "~/usrc/gawk-3.1.5/doc/gawk")
# (find-gawkfile "")
# (find-gawknode "Top")
# (find-gawknode "Nondecimal-numbers")
# (find-man "bc")
# (find-man "dc")
# (find-node "(libc)Parsing of Integers")
# (find-node "(libc)Line Input")




#####
#
# Recursive descent parser
# 2011nov01
#
#####

# «awkbookcode»  (to ".awkbookcode")
# «recursive-descent»  (to ".recursive-descent")
# (find-books "__comp/__comp.el" "awk")
# http://www.netlib.org/research/awkbookcode/
# http://www.netlib.org/research/awkbookcode/ch1
# http://www.netlib.org/research/awkbookcode/ch2
# http://www.netlib.org/research/awkbookcode/ch3
# http://www.netlib.org/research/awkbookcode/ch4
# http://www.netlib.org/research/awkbookcode/ch5
# http://www.netlib.org/research/awkbookcode/ch6
# http://www.netlib.org/research/awkbookcode/ch7
# http://www.netlib.org/research/awkbookcode/unbundle.awk

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rv /tmp/awkbookcode/
mkdir  /tmp/awkbookcode/
cd     /tmp/awkbookcode/
cat $S/http/www.netlib.org/research/awkbookcode/ch6 \
  | awk -f $S/http/www.netlib.org/research/awkbookcode/unbundle.awk

# (find-fline "/tmp/awkbookcode/")
# (find-fline "/tmp/awkbookcode/awk.parser")





#####
#
# The examples in the "Getting started" section of the manual
# 2019oct03
#
#####

# «getting-started» (to ".getting-started")
# (find-node "(gawk)Getting Started")
# (find-node "(gawk)Very Simple" "NF > 0")
# (find-node "(gawk)Two Rules")
# (find-node "(gawk)More Complex")
# (find-node "(gawk)Regexp")

# (find-gawknode "String Functions" "gsub(REGEXP")
# (find-gawknode "Bracket Expressions")




#####
#
# sub
# 2023may08
#
#####

# «sub»  (to ".sub")
# (find-gawknode "String Functions" "'sub(REGEXP")
# https://unix.stackexchange.com/questions/134212/extract-file-name-from-path-in-awk-program
# https://documentacoes.wordpress.com/2019/01/17/basename-and-dirname-commands-implemented-in-awk/
# https://groups.google.com/g/comp.lang.awk/c/eyqbS7ojRuQ

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
awk '
  function basename(file) {
    sub(".*/", "", file)
    return file
  }
  {print FILENAME, basename(FILENAME)}
' /path/to/file

awk '
  function basename(file, a, n) {
    n = split(file, a, "/")
    return a[n]
  }
  {print FILENAME, basename(FILENAME)}
' /path/to/file



#####
#
# txr
# 2021feb04
#
#####

# «txr»  (to ".txr")
# https://nongnu.org/txr/
# https://nongnu.org/txr/rosetta-solutions.html
# https://nongnu.org/txr/txr-pattern-language.html




http://www.cs.nott.ac.uk/~txa/g51mal/notes-6x.pdf




http://www.wra1th.plus.com/awk/awkfri.txt
http://www.mailsend-online.com/blog/along-came-awk.html

http://books.cat-v.org/computer-science/awk-programming-language/The_AWK_Programming_Language.pdf

https://jherrlin.github.io/posts/learn-awk/

https://news.ycombinator.com/item?id=13451454 The Awk Programming Language (1988) [pdf] (archive.org)

https://news.ycombinator.com/item?id=29528439 Cheating at a company group activity using Unix tools (medium.com/fundbox-engineering)
https://news.ycombinator.com/item?id=32569477 Unix legend, who owes us nothing, keeps fixing foundational Awk code (arstechnica.com)

https://news.ycombinator.com/item?id=32969238 What does $0=$2 in awk do? (kau.sh) - learning resources
https://maximullaris.com/goawk_cover.html
https://news.ycombinator.com/item?id=34393085 Awk: Power and Promise of a 40 yr old language (2021) (fosslife.org)
https://github.com/TheMozg/awk-raycaster
https://news.ycombinator.com/item?id=34438560 The State of the Awk (2020) (lwn.net)
https://news.ycombinator.com/item?id=34442528 A first person shooter in 571 lines of GNU Awk (2016) (github.com/themozg) ***
https://github.com/geary/awk/blob/master/LJPII.AWK
https://stackoverflow.com/questions/45420535/whats-the-most-robust-way-to-efficiently-parse-csv-using-awk
https://news.ycombinator.com/item?id=34280281 Learn to Process Text in Linux Using Grep, Sed, and Awk (linode.com)
https://news.ycombinator.com/item?id=33936366 Haskell, Ada, C++, Awk: An Experiment in Prototyping Productivity (1994) [pdf] (yale.edu)
https://news.ycombinator.com/item?id=32534173 Brian Kernighan adds Unicode support to Awk (github.com/onetrueawk) - groff / troff
https://irreal.org/blog/?p=10746 Brailsford & Kernighan on AWK
https://c2.com/doc/expense/ Expense Calculator - Ward Cunningham - awk
https://maximullaris.com/awk.html A fascination of Awk
https://maximullaris.com/awk_tech_notes.html
https://news.ycombinator.com/item?id=35339955 Awk Technical Notes (maximullaris.com)
https://maximullaris.com/bytebeat_gawk.html
https://news.ycombinator.com/item?id=36389755 Fhtagn – A tiny CLI programs tester written in Awk (maximullaris.com)
https://awk.dev/
https://news.ycombinator.com/item?id=37290356 CLI text processing with GNU awk (learnbyexample.github.io)
https://benhoyt.com/writings/awk-make/





#  Local Variables:
#  coding:               utf-8-unix
#  End: