fixed a few minor bugs

This commit is contained in:
2009-06-27 07:05:19 +00:00
parent 06d3d78abf
commit e337e01d46
105 changed files with 164 additions and 703 deletions

View File

@ -0,0 +1 @@
{ print $1, $3; } # print country name and population

View File

@ -0,0 +1,15 @@
BEGIN {
FS = "\t";
printf ("%10s %6s %5s %s\n\n",
"COUNTRY", "AREA", "POP", "CONTINENT");
}
{
printf ("%10s %6d %5d %s\n", $1, $2, $3, $4);
area = area + $2;
pop = pop + $3;
}
END {
printf ("\n%10s %6d %5d\n", "TOTAL", area, pop);
}

View File

@ -0,0 +1 @@
$3/$2 >= 0.5

View File

@ -0,0 +1 @@
$0 >= "M"

View File

@ -0,0 +1 @@
$1 < $4

View File

@ -0,0 +1 @@
$2 < $3

View File

@ -0,0 +1 @@
/Asia/

View File

@ -0,0 +1 @@
$4 ~ /Asia/

View File

@ -0,0 +1 @@
$4 !~ /Asia/

View File

@ -0,0 +1 @@
$0 ~ /Asia/

View File

@ -0,0 +1,3 @@
$2 !~ /^[0-9]+$/

View File

@ -0,0 +1 @@
$4 == "Asia" && $3 > 500

View File

@ -0,0 +1 @@
$4 == "Asia" || $4 == "Europe"

View File

@ -0,0 +1 @@
$4 ~ /^(Asia|Europe)$/

View File

@ -0,0 +1 @@
/Asia/ || /Europe/

View File

@ -0,0 +1 @@
/Asia|Europe/

View File

@ -0,0 +1 @@
/Canada/, /USA/

View File

@ -0,0 +1 @@
/Eurpoe/, /Africa/

View File

@ -0,0 +1 @@
FNR == 1, FNR == 5 { print FILENAME ": " $0; }

View File

@ -0,0 +1 @@
FNR <= 5 { print FILENAME ": " $0; }

View File

@ -0,0 +1 @@
$4 == "Asia" { print $1, 1000 * $2; }

View File

@ -0,0 +1,6 @@
#BEGIN { FS = "\t"; OFS = "\t"; }
BEGIN { FS = OFS = "\t"; }
$4 == "North America" { $4 = "NA"; }
$4 == "South America" { $4 = "SA"; }
{ print; }

View File

@ -0,0 +1,2 @@
BEGIN { FS = OFS = "\t"; }
{ $5 = 1000 * $3 / $2; print; }

View File

@ -0,0 +1,4 @@
$4 == "Asia" { pop = pop + $3; n = n + 1; }
END { print "Total population of the", n,
"Asian countries is", pop, "million.";
}

View File

@ -0,0 +1,6 @@
/Asia/ { pop["Asia"] += $3; }
/Europe/ { pop["Europe"] += $3; }
END { print "Asian population is", pop["Asia"], "million.";
print "European population is", pop["Europe"], "million.";
}

View File

@ -0,0 +1,3 @@
BEGIN { FS = "\t"; }
{ pop[$4] += $3; }
END { for (name in pop) print name, pop[name]; }

View File

@ -0,0 +1,17 @@
BEGIN { FS = "\t"; }
{ pop[$4] += $3; }
END {
# specifying a postion with + notation seems obsolete for sort
# on most platforms.
# sort -t'\t' +1rn => sort -t'\t' -k2 -rn
for (c in pop)
printf ("%15s\t%6d\n", c, pop[c]) | "sort -t'\t' -k2 -rn";
# the following two statements make the program behave
# consistently across different platforms.
# on some platforms, the sort command output has
# been delayed until the program exits.
close ("sort -t'\t' -k2 -rn");
sleep (1);
}

11
qse/regress/awk/cou.dat Normal file
View File

@ -0,0 +1,11 @@
USSR 8649 275 Asia
Canada 3852 25 North America
China 3705 1032 Asia
USA 3615 237 North America
Brazil 3286 134 South America
India 1267 746 Asia
Mexico 762 78 North America
France 211 55 Europe
Japan 144 120 Asia
Germany 96 61 Europe
England 94 56 Europe

View File

@ -0,0 +1,56 @@
#.H1 indent.awk
#.H2 Synopsis
#.P gawk -f indent.awk file.sh
#.H2 Download
#.P Download from <a href="http://lawker.googlecode.com/svn/fridge/lib/awk/indent.awk">LAWKER</a>
#.h2 Description
#.P
# This is part of Phil's AWK tutorial at
#<a href="http://www.bolthole.com/AWK.html">http://www.bolthole.com/AWK.html</a>.
# This program adjusts the indentation level based on which keywords are
# found in each line it encounters.
#.h2 Code
#.H3 doindent
#.PRE
function doindent(){
tmpindent=indent;
if(indent<0){
print "ERROR; indent level == " indent
}
while(tmpindent >0){
printf(" ");
tmpindent-=1;
}
}
#./PRE
#.H3 Out-denting
#.PRE
$1 == "done" { indent -=1; }
$1 == "fi" { indent -=1; }
$0 ~ /^}$/ { if(indent!=0) indent-=1; }
#./PRE
#.H3 Worker
#.P
# This is the 'default' action, that actually prints a line out.
# This gets called AS WELL AS any other matching clause, in the
# order they appear in this program.
# An "if" match is run AFTER we run this clause.
# A "done" match is run BEFORE we run this clause.
#.PRE
{
doindent();
print $0;
}
#./PRE
#.H3 In-denting
#.PRE
$0 ~ /if.*;[ ]*then/ { indent+=1; }
$0 ~ /for.*;[ ]*do/ { indent+=1; }
$0 ~ /while.*;[ ]*do/ { indent+=1; }
$1 == "then" { indent+=1; }
$1 == "do" { indent+=1; }
$0 ~ /^{$/ { indent+=1; }
#./PRE
#.H2 Author
#.P Philip Brown phil@bolthole.com

View File

@ -22,45 +22,76 @@ print_usage()
# MAIN #
###################
QSEAWK="../../cmd/awk/qseawk"
PROGS="
emp-001.awk/emp.d//
emp-002.awk/emp.d//
emp-003.awk/emp.d//
emp-004.awk/emp.d//
emp-005.awk/emp.d//
emp-006.awk/emp.d//
emp-007.awk/emp.d//
emp-008.awk/emp.d//
emp-009.awk/emp.d//
emp-010.awk/emp.d//
emp-011.awk/emp.d//
emp-012.awk/emp.d//
emp-013.awk/emp.d//
emp-014.awk/emp.d//
emp-015.awk/emp.d//
emp-016.awk/emp.d//
emp-017.awk/emp.d//
emp-018.awk/emp.d//
emp-019.awk/emp.d//
emp-020.awk/emp.d//
emp-021.awk/emp.d//
emp-022.awk/emp.d//
emp-023.awk/emp.d//
emp-024.awk/emp.d//
emp-025.awk/emp.d//
emp-026.awk/emp.d//
emp-027.awk/emp.d//
QSEAWK=${QSEAWK:=../../cmd/awk/qseawk}
quicksort.awk/quicksort.d//
quicksort2.awk/quicksort2.d//
asm.awk/asm.d1/asm.d2/
stripcomment.awk/stripcomment.d//
PROGS="
cou-001.awk/cou.dat//
cou-002.awk/cou.dat//
cou-003.awk/cou.dat//
cou-004.awk/cou.dat//
cou-005.awk/cou.dat//
cou-006.awk/cou.dat//
cou-007.awk/cou.dat//
cou-008.awk/cou.dat//
cou-009.awk/cou.dat//
cou-010.awk/cou.dat//
cou-011.awk/cou.dat//
cou-012.awk/cou.dat//
cou-013.awk/cou.dat//
cou-014.awk/cou.dat//
cou-015.awk/cou.dat//
cou-016.awk/cou.dat//
cou-017.awk/cou.dat//
cou-018.awk/cou.dat//
cou-019.awk/cou.dat//
cou-020.awk/cou.dat//
cou-021.awk/cou.dat//
cou-022.awk/cou.dat//
cou-023.awk/cou.dat//
cou-024.awk/cou.dat//
cou-025.awk/cou.dat//
cou-026.awk/cou.dat//
cou-027.awk/cou.dat//
emp-001.awk/emp.dat//
emp-002.awk/emp.dat//
emp-003.awk/emp.dat//
emp-004.awk/emp.dat//
emp-005.awk/emp.dat//
emp-006.awk/emp.dat//
emp-007.awk/emp.dat//
emp-008.awk/emp.dat//
emp-009.awk/emp.dat//
emp-010.awk/emp.dat//
emp-011.awk/emp.dat//
emp-012.awk/emp.dat//
emp-013.awk/emp.dat//
emp-014.awk/emp.dat//
emp-015.awk/emp.dat//
emp-016.awk/emp.dat//
emp-017.awk/emp.dat//
emp-018.awk/emp.dat//
emp-019.awk/emp.dat//
emp-020.awk/emp.dat//
emp-021.awk/emp.dat//
emp-022.awk/emp.dat//
emp-023.awk/emp.dat//
emp-024.awk/emp.dat//
emp-025.awk/emp.dat//
emp-026.awk/emp.dat//
emp-027.awk/emp.dat//
quicksort.awk/quicksort.dat//
quicksort2.awk/quicksort2.dat//
asm.awk/asm.s/asm.dat/
stripcomment.awk/stripcomment.dat//
wordfreq.awk/wordfreq.awk//
hanoi.awk//
indent.awk/regress.sh/
"
[ -x "${QSEAWK}" ] || {
[ -x "${QSEAWK}" ] ||
{
echo "ERROR: ${QSEAWK} not found"
exit 1;
}
@ -72,7 +103,7 @@ do
redinfile="`echo ${prog} | cut -d/ -f3`"
awkopts="`echo ${prog} | cut -d/ -f4`"
if [ -n "${redinfile}" ]
if [ -n "${redinfile}" ]
then
echo_so "${QSEAWK} ${awkopts} -f ${script} ${datafile} < ${redinfile}"
${QSEAWK} ${awkopts} -f ${script} ${datafile} < ${redinfile}

View File

@ -16,5 +16,3 @@ END {
for (word in freq)
print word, freq[word];
}