Lines Matching full:awk

8 #   See "awk -f test04.awk" near line 170
9 # and "awk -e ..." tests near line 415
23 testcmd "awk PATTERN input" "'/abc/' input" \
26 testcmd "awk SUBPATTERN input" "'/ab/' input" \
29 testcmd "awk FIELD input" "'{print \$2,\$3}' input" \
32 testcmd "awk FIELD input (out range)" "'{print \$2,\$8}' input" \
39 testing "awk FIELD input (single, multiple times)" \
40 "awk '{ print \$2,\$2,\$2,\$2,\$2,\$2,\$2,\$2,\$2,\$2 }' input" \
46 testcmd "awk CODE input" "'BEGIN { print \"$HEAD\"; } {
50 testcmd "awk '>' input" "'\$4>0' input" \
53 testcmd "awk '<' input" "'\$4<25' input" \
56 testcmd "awk '==' input" "'\$4==15' input" "mno pqr stu 15\n" "$FILE1" ""
58 testcmd "awk CMP input" "'\$1~/abc/' input" "abc def ghi 5\n" "$FILE1" ""
60 testcmd "awk COUNT input" "'BEGIN { count=0; } \$1~/abc/ { count++; } END {
63 testcmd "awk COLUMN input" "'{ print \$1 }' input" "abc\nghi\nmno\nstu\n" \
66 testcmd "awk SUM input" "'BEGIN { sum=0; } { sum=sum+\$4; } END {
69 testcmd "awk IF input" "'{ if(\$2 == \"jkl\") print \$1; }' input" "ghi\n" \
72 testing "awk FOR MUL input" \
73 "awk 'BEGIN { for(i=1;i<=3;i++) print \"square of\", i, \"is\",i*i; }'" \
76 testing "awk FOR ADD input" \
77 "awk 'BEGIN { for(i=1;i<=3;i++) print \"twice of\", i, \"is\",i+i; }'" \
80 testing "awk FOR SUB input" \
81 "awk 'BEGIN { for(i=1;i<=3;i++) print \"sub of\", i, \"is\",i-i; }'" \
84 testcmd "awk {FS:invalid} input1" "'BEGIN { FS=\"69793793\" } { print \$2
87 testcmd "awk -F invalid input1" "-F69793793 '{ print \$2 }' input" \
90 testcmd "awk {FS} input2" "'BEGIN { FS=\",\" } { print \$2 }' input" \
93 testcmd "awk -F input2" "-F\",\" '{ print \$2 }' input" \
96 testcmd "awk {FS} input3" "'BEGIN { FS=\":\" } { print \$2 }' input" \
99 testcmd "awk -F input3" "-F: '{ print \$2 }' input" "def\njkl\npqr\nvwx\n" \
102 testcmd "awk {OFS} {1} input" "'BEGIN { OFS=\"__\" } { print \$2 }' input" \
105 testcmd "awk {OFS} {1,2} input" "'BEGIN { OFS=\"__\" } { print \$2,\$3
108 testcmd "awk {NF} input" "'{print NF}' input" "4\n4\n4\n4\n" "$FILE1" ""
110 testcmd "awk {NR} input" "'{print NR}' input" "1\n2\n3\n4\n" "$FILE1" ""
112 testcmd "awk END{NR} input" "'END {print NR}' input" "4\n" "$FILE1" ""
114 testcmd "awk SPLIT input" "'{ split(\$0,arr,\" \"); if(arr[3] == \"abc\")
117 testcmd "awk SUBSTR input" "'{if (substr(\$0,1,3) == \"abc\") { print \$3 }
120 testcmd "awk SEARCH {PRINT} input" "'/ghi/ {print \$1,\$2,\$3,\$4}' input" \
123 testcmd "awk SEARCH {PRINTF} input" "'/ghi/ { printf \$1 \$2 \$3 \$4
126 testcmd "awk {PRINT with TAB} input" "'{print \$2,\"\t\",\$4}' input" \
129 testcmd "awk {PRINT 2,4} input" "'{print \$2,\$4}' input" \
132 testcmd "awk {PRINT 4,2} input" "'{print \$4,\$2}' input" \
135 testcmd "awk {PRINT X,Y} input" "'{print \$6,\$9}' input" \
138 testcmd "awk {PRINT} input" "'{ print }' input" "$FILE1" "$FILE1" ""
140 testcmd "awk INVALID_ARGS1 input" "'{ print x,y }' input" \
143 testcmd "awk INVALID_ARGS2 input" "'{ print \$4,\$5 }' input" \
146 testcmd "awk PATTERN input (not found)" "'/abcd/' input && echo 'yes'" \
149 testcmd "awk {PATTERN:-ve} input" "'/-5/' input" "abc def ghi -5\n" \
152 testcmd "awk FIELD input (high value)" "'{print \$99999}' input &&
158 FS=\" \"; } else { print \$3 } }" > test.awk
159 testcmd "awk -f test01.awk" "-f test.awk input" \
163 for (i=1; i <= 5; i++) { printf i \"-\" i*i \" \"; } }" > test.awk
164 testcmd "awk -f test02.awk" "-f test.awk" \
168 END { print \"End.\" }" > test.awk
169 testcmd "awk -f test03.awk" "-f test.awk" \
172 ### echo "{ if ( \$0 ~ /:/ ) {FS=\":\";} else {FS=\" \";} print \$3 }" > test.awk
173 ### testing "awk -f test04.awk" "awk -f test.awk input" \
178 ### This is wrong; gawk/mawk/bbawk/bwk awk agree that second ghi should not appear.
181 echo "{ if ( \$0 ~ /:/ ) {FS=\":\";} else {FS=\" \";} print \$3 }" > test.awk
182 testcmd "awk -f test04.awk" "-f test.awk input" \
187 print \"Average:\", total/lines; } else { print \"0\"; } }" > test.awk
188 testcmd "awk -f test05.awk" "-f test.awk input" \
191 echo "BEGIN{FS=\":\";}{if(\$2==\"pqr\"){print \"first one:\", \$1;}}" > test.awk
192 testcmd "awk -f test06.awk" "-f test.awk input" \
195 echo "{ print \$2; FS=\":\"; print \$2 }" > test.awk
196 testcmd "awk -f test07.awk" "-f test.awk input" \
199 echo "BEGIN { FS=\":\"; OFS=\":\"; } { \$2=\"\"; print }" > test.awk
200 testcmd "awk -f test09.awk" "-f test.awk input" \
205 echo "{ if (NF==8) { print \$8; } else if (NF==9) { print \$9; } }" > test.awk
206 testcmd "awk -f test10.awk" "-f test.awk input" "file\n" "$LLDATA" ""
208 echo "{ if (NR >= 1) { print NR;} }" > test.awk
209 testcmd "awk -f test11.awk" "-f test.awk input" "1\n2\n" "$LLDATA" ""
211 echo "BEGIN { RS=\"\"; FS=\"\n\" } { print \$2,\$3; }" > test.awk
212 testcmd "awk -f test12.awk" "-f test.awk input" \
216 echo "BEGIN { RS=\" \"; } { print; }" > test.awk
217 testcmd "awk -f test13.awk" "-f test.awk input" "$L\n" "$FILE1" ""
220 echo "BEGIN { ORS=\"\r\n\" } { print }" > test.awk
221 testcmd "awk -f test14.awk" "-f test.awk input" "$L" "$FILE1" ""
223 echo "BEGIN { f=\"\"; }{ if(f != FILENAME){ f=FILENAME; print f }}" > test.awk
224 testcmd "awk -f test15.awk" "-f test.awk input" "input\n" "$FILE1" ""
227 NR,\"line:\"; } else { print \"ERROR\",FILENAME,NR;}}}" > test.awk
228 testcmd "awk -f test16.awk" "-f test.awk input" \
235 print count[i], username[i] } } " > test.awk
236 testcmd "awk -f test17.awk" "-f test.awk input" "1 $USER\n" "$LLDATA" ""
238 echo "{ usrname[\$3]++;}END{for(i in usrname){print usrname[i],i;} }" > test.awk
239 testcmd "awk -f test18.awk" "-f test.awk input" "1 \n1 $USER\n" "$LLDATA" ""
242 print username[i], i; } }" > test.awk
243 testcmd "awk -f test19.awk" "-f test.awk input" "1 $USER\n" "$LLDATA" ""
246 for (i in username) { if (i != \"\") { print username[i], i; }}}" > test.awk
247 testcmd "awk -f test20.awk" "-f test.awk input" "1 $USER\n" "$LLDATA" ""
249 echo "{ printf \"%5s %3d\n\", \$3, \$4; }" > test.awk
250 testcmd "awk -f test22.awk" "-f test.awk input" \
254 { printf(format2, \$1, \$4); }" > test.awk
255 testcmd "awk -f test23.awk" "-f test.awk input" \
259 printf(\"i=%d\n\", i) > \"ConcatedFile_a\" i; } }" > test.awk
260 testcmd "awk -f test24.awk" "-f test.awk && cat ConcatedFile_a1 &&
269 print prefix \$0; } else { print; } }" > test.awk
270 testcmd "awk -f test26.awk" "-f test.awk input" "$L1$L2$L3$L4" "$FILE1" ""
274 line = line \$0; } else { printf(\"%d\", NR); } } print line; }" > test.awk
275 testcmd "awk -f test27.awk" "-f test.awk input" "$FILE1" "$FILE1" ""
278 printf \"%d \",x } print \"\" }" > test.awk
279 testcmd "awk -f test28.awk" "-f test.awk" \
282 echo "{ i = 1; while (i <= 2) { print \$i; i++ } }" > test.awk
283 testcmd "awk -f test29.awk" "-f test.awk input" \
290 echo "{ i = 1; do { print \$0; i++ } while (i <= 3) }" > test.awk
291 testcmd "awk -f test30.awk" "-f test.awk input" "$L1$L2$L3$L4" "$FILE1" ""
293 echo "{ for (i = 1; i <= 3; i++) print \$i }" > test.awk
294 testcmd "awk -f test31.awk" "-f test.awk input" \
299 else { printf \"%d is prime\n\", num } }" > test.awk
300 testcmd "awk -f test32.awk" "-f test.awk input" \
303 # Mod in case prog name is not 'awk'
304 ## echo "BEGIN { for (i = 0; i < ARGC; i++) { print ARGV[i] } }" > test.awk
305 ## testcmd "awk -f test33.awk" "-f test.awk input1 input2 input3 input4" \
306 ## "awk\ninput1\ninput2\ninput3\ninput4\n" "$FILE1" ""
307 echo "BEGIN { for (i = 1; i < ARGC; i++) { print ARGV[i] } }" > test.awk
308 testcmd "awk -f test33.awk" "-f test.awk input1 input2 input3 input4" \
311 echo "NR == 2 { NR = 17 } { print NR }" > test.awk
312 testcmd "awk -f test34.awk" "-f test.awk input" "1\n17\n18\n19\n" \
315 echo "BEGIN{n=0;}/abc/{++n;}END{print \"abc appears\",n,\"times\"}" > test.awk
316 testcmd "awk -f test35.awk" "-f test.awk input" "abc appears 2 times\n" \
319 echo "{ print \"Square root of\", \$1, \"is\", sqrt(\$1) }" > test.awk
320 testcmd "awk -f test36.awk" "-f test.awk input" \
324 echo "\$1 == \"foo\" { print \$2 }" > test.awk
325 testcmd "awk -f test37.awk" "-f test.awk input" "bar\n" "$FILE5" ""
327 echo "/2400/ && /foo/" > test.awk
328 testcmd "awk -f test38.awk" "-f test.awk input" "" "$FILE5" ""
330 echo "/2400/ || /foo/" > test.awk
331 testcmd "awk -f test39.awk" "-f test.awk input" "$FILE5" "$FILE5" ""
333 echo "! /foo/" > test.awk
334 testcmd "awk -f test40.awk" "-f test.awk input" "abc def 2400\n" "$FILE5" ""
336 echo "\$1 ~ /foo/ { print \$2 }" > test.awk
337 testcmd "awk -f test41.awk" "-f test.awk input" "bar\n" "$FILE5" ""
339 echo "{ if (! (\$0 ~ /foo/)) print }" > test.awk
340 testcmd "awk -f test42.awk" "-f test.awk input" "abc def 2400\n" "$FILE5" ""
344 echo "{ print \"F1:\", \$1 }" > test.awk
345 testcmd "awk -f test43.awk" "-f test.awk input" "F1: foo\nF1: abc\n" \
348 echo "{ sum = \$2 + \$3 + \$4 ; avg = sum / 3; print \$1, avg }" > test.awk
349 testcmd "awk -f test44.awk" "-f test.awk input" \
352 echo "{ print \$1 > \"list1\"; print \$2 > \"list2\" }" > test.awk
353 testcmd "awk -f test45.awk" "-f test.awk input && cat list1 && cat list2" \
357 echo "{ print \$(2*2) }" > test.awk
358 testcmd "awk -f test46.awk" "-f test.awk input" "58\n93\n89\n" "$FILE6" ""
360 echo "{ sub(/a+/,\"<A>\"); print }" > test.awk
361 testcmd "awk -f test47.awk" "-f test.awk input" \
365 print l[i]} }" > test.awk
366 testcmd "awk -f test48.awk" "-f test.awk input" \
373 testcmd "awk Print line longer than 12" "'length(\$0) > 12' input" \
377 testcmd "awk Print first two field opposite order" "'{ print \$2, \$1 }' input" \
381 testcmd "awk filter data" "'{ print \$5 }' input" \
387 testcmd "awk print selected lines" "'/abcd/' input" \
394 testcmd "awk print selected fields" "'{print \$2, \$4}' input" \
399 testcmd "awk FS" "'BEGIN {FS=k;lksa;lkf;l} {print \$2}' input" "b\nr\nh\nx\nn\n" "$FILE11" ""
402 FS=\" \"; } else { print \$3 } }" > test.awk
403 testcmd "awk -v var=val -f test.awk" "-v var=2 -f test.awk input" \
409 FS=\" \"; } else { print \$3 } }" > test.awk
410 testcmd "awk -v myvar=val -f file1 file" "-v myvar=$2 -f test.awk testfile1.txt testfile2.txt" "ghi…
412 ### The -e option is non-standard. gawk and bbawk accept it; mawk and goawk do not, bwk awk says un…
416 ###testing "awk -e print print ARGC file1 file2" "awk -e '{ print \$1; print ARGC }' testfile1.txt …
417 ###testing "awk -e print ARGC file" "awk -e '{ print ARGC }' testfile1.txt" "2\n2\n2\n2\n2\n" "$FIL…
418 ###testing "awk -e print print ARGC input" "awk -e '{ print \$1; print ARGC }' input" "abc\n2\nghi\…
444 # A bug in earlier versions (also in busybox awk) cause infinite output on "null RS" test
492 testcmd "awk -e print print ARGC file1 file2" "'{ print \$1; print ARGC }' testfile1.txt testfile2.…
493 testcmd "awk -e print ARGC file" "'{ print ARGC }' testfile1.txt" "2\n2\n2\n2\n2\n" "$FILE1" ""
494 testcmd "awk -e print print ARGC input" "'{ print \$1; print ARGC }' input" "abc\n2\nghi\n2\nmno\n2…
496 rm test.awk testfile1.txt testfile2.txt