|
Warning: this is an htmlized version!
The original is across this link, 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.
#
# 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")
# «.getline» (to "getline")
# (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
#*
#####
#
# 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
#
#####
# 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")
http://www.wra1th.plus.com/awk/awkfri.txt
# Local Variables:
# coding: raw-text-unix
# ee-delimiter-hash: "\n#*\n"
# ee-delimiter-percent: "\n%*\n"
# ee-anchor-format: "«%s»"
# End: