Package list libmawk / debian/latest doc / lmawk.1.html
debian/latest

Tree @debian/latest (Download .tar.gz)

lmawk.1.html @debian/latestraw · history · blame

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
<!-- Creator     : groff version 1.22.3 -->
<!-- CreationDate: Sun Nov 11 07:32:01 2018 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
       p       { margin-top: 0; margin-bottom: 0; vertical-align: top }
       pre     { margin-top: 0; margin-bottom: 0; vertical-align: top }
       table   { margin-top: 0; margin-bottom: 0; vertical-align: top }
       h1      { text-align: center }
</style>
<title>LMAWK</title>

</head>
<body>

<h1 align="center">LMAWK</h1>

<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#OPTIONS">OPTIONS</a><br>
<a href="#THE AWK LANGUAGE">THE AWK LANGUAGE</a><br>
<a href="#EXAMPLES">EXAMPLES</a><br>
<a href="#COMPATIBILITY ISSUES">COMPATIBILITY ISSUES</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#AUTHOR">AUTHOR</a><br>

<hr>


<h2>NAME
<a name="NAME"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em">lmawk &minus;
pattern scanning and text processing language</p>

<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em"><b>lmawk</b>
[&minus;<b>W</b> <i>option</i>] [&minus;<b>F</b>
<i>value</i>] [&minus;<b>v</b> <i>var=value</i>]
[&minus;&minus;] &rsquo;program text&rsquo; [file ...]
<b><br>
lmawk</b> [&minus;<b>W</b> <i>option</i>] [&minus;<b>F</b>
<i>value</i>] [&minus;<b>v</b> <i>var=value</i>]
[&minus;<b>f</b> <i>program-file</i>] [&minus;&minus;] [file
...]</p>

<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em"><b>lmawk</b> is
an interpreter for the AWK Programming Language derived from
mawk. The AWK language is useful for manipulation of data
files, text retrieval and processing, and for prototyping
and experimenting with algorithms. <b>lmawk</b> is a <i>new
awk</i> meaning it implements the AWK language as defined in
Aho, Kernighan and Weinberger, <i>The AWK Programming
Language,</i> Addison-Wesley Publishing, 1988. (Hereafter
referred to as the AWK book.) <b>mawk</b> conforms to the
Posix 1003.2 (draft 11.3) definition of the AWK language
which contains a few features not described in the AWK book,
and <b>mawk</b> provides a small number of extensions.</p>

<p style="margin-left:11%; margin-top: 1em">An AWK program
is a sequence of <i>pattern {action}</i> pairs and function
definitions. Short programs are entered on the command line
usually enclosed in &rsquo; &rsquo; to avoid shell
interpretation. Longer programs can be read in from a file
with the &minus;f option. Data input is read from the list
of files on the command line or from standard input when the
list is empty. The input is broken into records as
determined by the record separator variable, <b>RS</b>.
Initially, <b>RS</b> = &quot;\n&quot; and records are
synonymous with lines. Each record is compared against each
<i>pattern</i> and if it matches, the program text for
<i>{action}</i> is executed.</p>

<h2>OPTIONS
<a name="OPTIONS"></a>
</h2>


<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="18%">


<p style="margin-top: 1em">&minus;<b>F</b> <i>value</i></p></td>
<td width="5%"></td>
<td width="66%">


<p style="margin-top: 1em">sets the field separator,
<b>FS</b>, to <i>value</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="18%">


<p>&minus;<b>f</b> <i>file</i></p></td>
<td width="5%"></td>
<td width="66%">


<p>Program text is read from <i>file</i> instead of from
the command line. Multiple <b>&minus;f</b> options are
allowed. As a libmawk extension, if file name starts with
plus (&rsquo;+&rsquo;), it is not loaded if the same file
has been loaded already by a previous -f or include from any
of the scripts already loaded.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="18%">


<p>&minus;<b>b</b> <i>file</i></p></td>
<td width="5%"></td>
<td width="66%">


<p>Program bytecode is read from <i>file</i> . Multiple
<b>&minus;b</b> options are allowed. Bytecode can be
generated using -Wcompile. Libmawk may refuse to load
bytecode generated on a different system if byte order, type
sizes or dump version differs.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="18%">


<p>&minus;<b>v</b> <i>var=value</i></p></td>
<td width="5%"></td>
<td width="66%">


<p>assigns <i>value</i> to program variable <i>var</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="18%">


<p>&minus;&minus;</p></td>
<td width="5%"></td>
<td width="66%">


<p>indicates the unambiguous end of options.</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">The above
options will be available with any Posix compatible
implementation of AWK, and implementation specific options
are prefaced with <b>&minus;W</b>. <b>lmawk</b> provides
six:</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p style="margin-top: 1em">&minus;<b>W</b> version</p></td>
<td width="2%"></td>
<td width="66%">


<p style="margin-top: 1em"><b>lmawk</b> writes its version
and copyright to stdout and compiled limits to stderr and
exits 0.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> debug</p></td>
<td width="2%"></td>
<td width="66%">


<p>include location info in the compiled code; location
information is visible in the dump and when debugging
libmawk.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> dump</p></td>
<td width="2%"></td>
<td width="66%">


<p>writes an assembler like listing of the internal
representation of the program to stdout and exits 0 (on
successful compilation).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> dumpsym</p></td>
<td width="2%"></td>
<td width="66%">


<p>writes a list of global symbols to stdout and exits 0
(on successful compilation).</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> compile</p></td>
<td width="2%"></td>
<td width="66%">


<p>writes a binary dump of the bytecode to stdout. This
bytecode can be loaded using the &minus;<b>b</b> switch.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> interactive</p></td>
<td width="2%"></td>
<td width="66%">


<p>sets unbuffered writes to stdout and line buffered reads
from stdin. Records from stdin are lines regardless of the
value of <b>RS</b>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> maxmem=<i>num</i></p></td>
<td width="2%"></td>
<td width="66%">


<p>limit dynamic memory allocation during compilation and
execution to <i>num</i> bytes and exit with
out-of-the-memory error if more memory is to be allocated.
Optional suffixes are k for kilobyte and m for megabyte. 0
means unlimited, which is also the default.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> exec <i>file</i></p></td>
<td width="2%"></td>
<td width="66%">


<p>Program text is read from <i>file</i> and this is the
last option. Useful on systems that support the <b>#!</b>
&quot;magic number&quot; convention for executable
scripts.</p> </td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> sprintf=<i>num</i></p></td>
<td width="2%"></td>
<td width="66%">


<p>adjusts the size of <b>lmawk&rsquo;s</b> internal
sprintf buffer to <i>num</i> bytes. More than rare use of
this option indicates <b>lmawk</b> should be recompiled.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="21%">


<p>&minus;<b>W</b> posix_space</p></td>
<td width="2%"></td>
<td width="66%">


<p>forces <b>lmawk</b> not to consider &rsquo;\n&rsquo; to
be space.</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">The short forms
<b>&minus;W</b>[vdiesp] are recognized and on some systems
<b>&minus;W</b>e is mandatory to avoid command line length
limitations.</p>

<h2>THE AWK LANGUAGE
<a name="THE AWK LANGUAGE"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em"><b>1. Program
structure</b> <br>
An AWK program is a sequence of <i>pattern {action}</i>
pairs and user function definitions.</p>

<p style="margin-left:11%; margin-top: 1em">A pattern can
be:</p>

<p style="margin-left:22%;"><b>BEGIN <br>
END</b> <br>
expression <br>
expression , expression</p>

<p style="margin-left:11%; margin-top: 1em">One, but not
both, of <i>pattern {action}</i> can be omitted. If
<i>{action}</i> is omitted it is implicitly { print }. If
<i>pattern</i> is omitted, then it is implicitly matched.
<b>BEGIN</b> and <b>END</b> patterns require an action.</p>

<p style="margin-left:11%; margin-top: 1em">Statements are
terminated by newlines, semi-colons or both. Groups of
statements such as actions or loop bodies are blocked via {
... } as in C. The last statement in a block doesn&rsquo;t
need a terminator. Blank lines have no meaning; an empty
statement is terminated with a semi-colon. Long statements
can be continued with a backslash, \. A statement can be
broken without a backslash after a comma, left brace,
&amp;&amp;, ||, <b>do</b>, <b>else</b>, the right
parenthesis of an <b>if</b>, <b>while</b> or <b>for</b>
statement, and the right parenthesis of a function
definition. A comment starts with # and extends to, but does
not include the end of line.</p>

<p style="margin-left:11%; margin-top: 1em">The following
statements control program flow inside blocks.</p>

<p style="margin-left:22%; margin-top: 1em"><b>if</b> (
<i>expr</i> ) <i>statement</i></p>

<p style="margin-left:22%; margin-top: 1em"><b>if</b> (
<i>expr</i> ) <i>statement</i> <b>else</b>
<i>statement</i></p>

<p style="margin-left:22%; margin-top: 1em"><b>while</b> (
<i>expr</i> ) <i>statement</i></p>

<p style="margin-left:22%; margin-top: 1em"><b>do</b>
<i>statement</i> <b>while</b> ( <i>expr</i> )</p>

<p style="margin-left:22%; margin-top: 1em"><b>for</b> (
<i>opt_expr</i> ; <i>opt_expr</i> ; <i>opt_expr</i> )
<i>statement</i></p>

<p style="margin-left:22%; margin-top: 1em"><b>for</b> (
<i>var</i> <b>in</b> <i>array</i> ) <i>statement</i></p>


<p style="margin-left:22%; margin-top: 1em"><b>continue</b></p>


<p style="margin-left:22%; margin-top: 1em"><b>break</b></p>

<p style="margin-left:11%; margin-top: 1em"><b>2. Data
types, conversion and comparison</b> <br>
There are two basic data types, numeric and string. Numeric
constants can be integer like &minus;2, decimal like 1.08,
or in scientific notation like &minus;1.1e4 or .28E&minus;3.
All numbers are represented internally and all computations
are done in floating point arithmetic. So for example, the
expression 0.2e2 == 20 is true and true is represented as
1.0.</p>

<p style="margin-left:11%; margin-top: 1em">String
constants are enclosed in double quotes.</p>

<p align="center" style="margin-top: 1em">&quot;This is a
string with a newline at the end.\n&quot;</p>

<p style="margin-top: 1em">Strings can be continued across
a line by escaping (\) the newline. The following escape
sequences are recognized.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\\</p></td>
<td width="8%">
</td>
<td width="69%">


<p>\</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\&quot;</p></td>
<td width="8%">
</td>
<td width="69%">


<p>&quot;</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\a</p></td>
<td width="8%">
</td>
<td width="69%">


<p>alert, ascii 7</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\b</p></td>
<td width="8%">
</td>
<td width="69%">


<p>backspace, ascii 8</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\t</p></td>
<td width="8%">
</td>
<td width="69%">


<p>tab, ascii 9</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\n</p></td>
<td width="8%">
</td>
<td width="69%">


<p>newline, ascii 10</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\v</p></td>
<td width="8%">
</td>
<td width="69%">


<p>vertical tab, ascii 11</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\f</p></td>
<td width="8%">
</td>
<td width="69%">


<p>formfeed, ascii 12</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\r</p></td>
<td width="8%">
</td>
<td width="69%">


<p>carriage return, ascii 13</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\ddd</p></td>
<td width="8%">
</td>
<td width="69%">


<p>1, 2 or 3 octal digits for ascii ddd</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>\xhh</p></td>
<td width="8%">
</td>
<td width="69%">


<p>1 or 2 hex digits for ascii hh</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">If you escape
any other character \c, you get \c, i.e., <b>lmawk</b>
ignores the escape.</p>

<p style="margin-left:11%; margin-top: 1em">There are
really three basic data types; the third is <i>number and
string</i> which has both a numeric value and a string value
at the same time. User defined variables come into existence
when first referenced and are initialized to <i>null</i>, a
number and string value which has numeric value 0 and string
value &quot;&quot;. Non-trivial number and string typed data
come from input and are typically stored in fields. (See
section 4).</p>

<p style="margin-left:11%; margin-top: 1em">The type of an
expression is determined by its context and automatic type
conversion occurs if needed. For example, to evaluate the
statements</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>y = x + 2 ; z = x &quot;hello&quot;</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">The value
stored in variable y will be typed numeric. If x is not
numeric, the value read from x is converted to numeric
before it is added to 2 and stored in y. The value stored in
variable z will be typed string, and the value of x will be
converted to string if necessary and concatenated with
&quot;hello&quot;. (Of course, the value and type stored in
x is not changed by any conversions.) A string expression is
converted to numeric using its longest numeric prefix as
with <i>atof</i>(3). A numeric expression is converted to
string by replacing <i>expr</i> with <b>sprintf(CONVFMT</b>,
<i>expr</i>), unless <i>expr</i> can be represented on the
host machine as an exact integer then it is converted to
<b>sprintf</b>(&quot;%d&quot;, <i>expr</i>).
<b>Sprintf()</b> is an AWK built-in that duplicates the
functionality of <i>sprintf</i>(3), and <b>CONVFMT</b> is a
built-in variable used for internal conversion from number
to string and initialized to &quot;%.6g&quot;. Explicit type
conversions can be forced, <i>expr</i> &quot;&quot; is
string and <i>expr</i>+0 is numeric.</p>

<p style="margin-left:11%; margin-top: 1em">To evaluate,
<i>expr</i>1 <b>rel-op</b> <i>expr</i>2, if both operands
are numeric or number and string then the comparison is
numeric; if both operands are string the comparison is
string; if one operand is string, the non-string operand is
converted and the comparison is string. The result is
numeric, 1 or 0.</p>

<p style="margin-left:11%; margin-top: 1em">In boolean
contexts such as, <b>if</b> ( <i>expr</i> )
<i>statement</i>, a string expression evaluates true if and
only if it is not the empty string &quot;&quot;; numeric
values if and only if not numerically zero.</p>

<p style="margin-left:11%; margin-top: 1em"><b>3. Regular
expressions</b> <br>
In the AWK language, records, fields and strings are often
tested for matching a <i>regular expression</i>. Regular
expressions are enclosed in slashes, and</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p><i>expr</i> ~ /<i>r</i>/</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">is an AWK
expression that evaluates to 1 if <i>expr</i>
&quot;matches&quot; <i>r</i>, which means a substring of
<i>expr</i> is in the set of strings defined by <i>r</i>.
With no match the expression evaluates to 0; replacing ~
with the &quot;not match&quot; operator, !~ , reverses the
meaning. As pattern-action pairs,</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>/<i>r</i>/ { <i>action</i> } and <b>$0</b> ~ /<i>r</i>/
{ <i>action</i> }</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">are the same,
and for each input record that matches <i>r</i>,
<i>action</i> is executed. In fact, /<i>r</i>/ is an AWK
expression that is equivalent to (<b>$0</b> ~ /<i>r</i>/)
anywhere except when on the right side of a match operator
or passed as an argument to a built-in function that expects
a regular expression argument.</p>

<p style="margin-left:11%; margin-top: 1em">AWK uses
extended regular expressions as with <i>egrep</i>(1). The
regular expression metacharacters, i.e., those with special
meaning in regular expressions are</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>&nbsp;^ $ . [ ] | ( ) * + ?</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">Regular
expressions are built up from characters as follows:</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="18%">


<p style="margin-top: 1em"><i>c</i></p></td>
<td width="2%"></td>
<td width="58%">


<p style="margin-top: 1em">matches any non-metacharacter
<i>c</i>.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="18%">


<p>\<i>c</i></p></td>
<td width="2%"></td>
<td width="58%">


<p>matches a character defined by the same escape sequences
used in string constants or the literal character <i>c</i>
if \<i>c</i> is not an escape sequence.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="18%">


<p>.</p></td>
<td width="2%"></td>
<td width="58%">


<p>matches any character (including newline).</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="18%">


<p>^</p></td>
<td width="2%"></td>
<td width="58%">


<p>matches the front of a string.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="18%">


<p>$</p></td>
<td width="2%"></td>
<td width="58%">


<p>matches the back of a string.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="18%">


<p>[c1c2c3...]</p></td>
<td width="2%"></td>
<td width="58%">


<p>matches any character in the class c1c2c3... . An
interval of characters is denoted c1&minus;c2 inside a class
[...].</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="18%">


<p>[^c1c2c3...]</p></td>
<td width="2%"></td>
<td width="58%">


<p>matches any character not in the class c1c2c3...</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">Regular
expressions are built up from other regular expressions as
follows:</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="10%">


<p style="margin-top: 1em"><i>r</i>1<i>r</i>2</p></td>
<td width="10%"></td>
<td width="58%">


<p style="margin-top: 1em">matches <i>r</i>1 followed
immediately by <i>r</i>2 (concatenation).</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="10%">


<p><i>r</i>1 | <i>r</i>2</p></td>
<td width="10%"></td>
<td width="58%">


<p>matches <i>r</i>1 or <i>r</i>2 (alternation).</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="10%">


<p><i>r</i>*</p></td>
<td width="10%"></td>
<td width="58%">


<p>matches <i>r</i> repeated zero or more times.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="10%">


<p><i>r</i>+</p></td>
<td width="10%"></td>
<td width="58%">


<p>matches <i>r</i> repeated one or more times.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="10%">


<p><i>r</i>?</p></td>
<td width="10%"></td>
<td width="58%">


<p>matches <i>r</i> zero or once.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="10%">


<p>(<i>r</i>)</p></td>
<td width="10%"></td>
<td width="58%">


<p>matches <i>r</i>, providing grouping.</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">The increasing
precedence of operators is alternation, concatenation and
unary (*, + or ?).</p>

<p style="margin-left:11%; margin-top: 1em">For
example,</p>


<p style="margin-left:11%; margin-top: 1em">/^[_a&minus;zA-Z][_a&minus;zA&minus;Z0&minus;9]*$/
and</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">



<p>/^[&minus;+]?([0&minus;9]+\.?|\.[0&minus;9])[0&minus;9]*([eE][&minus;+]?[0&minus;9]+)?$/</p> </td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">are matched by
AWK identifiers and AWK numeric constants respectively. Note
that . has to be escaped to be recognized as a decimal
point, and that metacharacters are not special inside
character classes.</p>

<p style="margin-left:11%; margin-top: 1em">Any expression
can be used on the right hand side of the ~ or !~ operators
or passed to a built-in that expects a regular expression.
If needed, it is converted to string, and then interpreted
as a regular expression. For example,</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>BEGIN { identifier =
&quot;[_a&minus;zA&minus;Z][_a&minus;zA&minus;Z0&minus;9]*&quot;
}</p> </td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>$0 ~ &quot;^&quot; identifier</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">prints all
lines that start with an AWK identifier.</p>

<p style="margin-left:11%; margin-top: 1em"><b>lmawk</b>
recognizes the empty regular expression, //, which matches
the empty string and hence is matched by any string at the
front, back and between every character. For example,</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>echo abc | lmawk { gsub(//, &quot;X&quot;) ; print }</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>XaXbXcX</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em"><b>4. Records
and fields</b> <br>
Records are read in one at a time, and stored in the
<i>field</i> variable <b>$0</b>. The record is split into
<i>fields</i> which are stored in <b>$1</b>, <b>$2</b>, ...,
<b>$NF</b>. The built-in variable <b>NF</b> is set to the
number of fields, and <b>NR</b> and <b>FNR</b> are
incremented by 1. Fields above <b>$NF</b> are set to
&quot;&quot;.</p>

<p style="margin-left:11%; margin-top: 1em">Assignment to
<b>$0</b> causes the fields and <b>NF</b> to be recomputed.
Assignment to <b>NF</b> or to a field causes <b>$0</b> to be
reconstructed by concatenating the <b>$i&rsquo;s</b>
separated by <b>OFS</b>. Assignment to a field with index
greater than <b>NF</b>, increases <b>NF</b> and causes
<b>$0</b> to be reconstructed.</p>

<p style="margin-left:11%; margin-top: 1em">Data input
stored in fields is string, unless the entire field has
numeric form and then the type is number and string. For
example,</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>echo 24 24E |</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>lmawk &rsquo;{ print($1&gt;100, $1&gt;&quot;100&quot;,
$2&gt;100, $2&gt;&quot;100&quot;) }&rsquo;</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>0 1 1 1</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em"><b>$0</b> and
<b>$2</b> are string and <b>$1</b> is number and string. The
first comparison is numeric, the second is string, the third
is string (100 is converted to &quot;100&quot;), and the
last is string.</p>

<p style="margin-left:11%; margin-top: 1em"><b>5.
Expressions and operators</b> <br>
The expression syntax is similar to C. Primary expressions
are numeric constants, string constants, variables, fields,
arrays and function calls. The identifier for a variable,
array or function can be a sequence of letters, digits and
underscores, that does not start with a digit. Variables are
not declared; they exist when first referenced and are
initialized to <i>null</i>.</p>

<p style="margin-left:11%; margin-top: 1em">New expressions
are composed with the following operators in order of
increasing precedence.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>assignment</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>= += &minus;= *= /= %= ^=</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>conditional</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>? :</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>logical or</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>||</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>logical and</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>&amp;&amp;</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>array membership</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p><b>in</b></p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>matching</i></p></td>
<td width="8%"></td>
<td width="7%">
</td>
<td width="62%">


<p>~ !~</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>relational</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>&lt; &gt; &lt;= &gt;= == !=</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>concatenation</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>(no explicit operator)</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>add ops</i></p></td>
<td width="8%"></td>
<td width="7%">
</td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>+ &minus;</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>mul ops</i></p></td>
<td width="8%"></td>
<td width="7%">
</td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>* / %</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>unary</i></p></td>
<td width="8%"></td>
<td width="7%">
</td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>+ &minus;</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>logical not</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>!</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>exponentiation</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>^</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>inc and dec</i></p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>++ &minus;&minus; (both post and pre)</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p><i>field</i></p></td>
<td width="8%"></td>
<td width="7%">
</td>
<td width="62%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="62%">


<p>$</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">Assignment,
conditional and exponentiation associate right to left; the
other operators associate left to right. Any expression can
be parenthesized.</p>

<p style="margin-left:11%; margin-top: 1em"><b>6.
Arrays</b> <br>
Awk provides one-dimensional arrays. Array elements are
expressed as <i>array</i>[<i>expr</i>]. <i>Expr</i> is
internally converted to string type, so, for example, A[1]
and A[&quot;1&quot;] are the same element and the actual
index is &quot;1&quot;. Arrays indexed by strings are called
associative arrays. Initially an array is empty; elements
exist when first accessed. An expression, <i>expr</i>
<b>in</b> <i>array</i> evaluates to 1 if
<i>array</i>[<i>expr</i>] exists, else to 0.</p>

<p style="margin-left:11%; margin-top: 1em">There is a form
of the <b>for</b> statement that loops over each index of an
array.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p><b>for</b> ( <i>var</i> <b>in</b> <i>array</i> )
<i>statement</i></p> </td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">sets <i>var</i>
to each index of <i>array</i> and executes <i>statement</i>.
The order that <i>var</i> transverses the indices of
<i>array</i> is not defined.</p>

<p style="margin-left:11%; margin-top: 1em">The statement,
<b>delete</b> <i>array</i>[<i>expr</i>], causes
<i>array</i>[<i>expr</i>] not to exist. <b>lmawk</b>
supports an extension, <b>delete</b> <i>array</i>, which
deletes all elements of <i>array</i>.</p>


<p style="margin-left:11%; margin-top: 1em">Multidimensional
arrays are synthesized with concatenation using the built-in
variable <b>SUBSEP</b>.
<i>array</i>[<i>expr</i>1,<i>expr</i>2] is equivalent to
<i>array</i>[<i>expr</i>1 <b>SUBSEP</b> <i>expr</i>2].
Testing for a multidimensional element uses a parenthesized
index, such as</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>if ( (i, j) in A ) print A[i, j]</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em"><b>7.
Builtin-variables</b> <br>
The following variables are built-in and initialized before
program execution.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p style="margin-top: 1em"><b>ARGC</b></p></td>
<td width="3%"></td>
<td width="63%">


<p style="margin-top: 1em">number of command line
arguments.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>ARGV</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>array of command line arguments, 0..ARGC-1.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>CONVFMT</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>format for internal conversion of numbers to string,
initially = &quot;%.6g&quot;.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>ENVIRON</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>array indexed by environment variables. An environment
string, <i>var=value</i> is stored as
<b>ENVIRON</b>[<i>var</i>] = <i>value</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>FILENAME</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>name of the current input file.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>FNR</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>current record number in <b>FILENAME</b>.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>FS</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>splits records into fields as a regular expression.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>NF</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>number of fields in the current record.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>NR</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>current record number in the total input stream.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>OFMT</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>format for printing numbers; initially =
&quot;%.6g&quot;.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>OFS</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>inserted between fields on output, initially = &quot;
&quot;.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>ORS</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>terminates each record on output, initially =
&quot;\n&quot;.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>RLENGTH</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>length set by the last call to the built-in function,
<b>match()</b>.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>RS</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>input record separator, initially = &quot;\n&quot;.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>RSTART</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>index set by the last call to <b>match()</b>.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>SUBSEP</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>used to build multiple array subscripts, initially =
&quot;\034&quot;.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>ERRNO</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>misc built-in functions (libmawk extensions) use this
variable to rerport error. All extension calls will set this
variable before returning, therefor ERRNO holds the result
of the last call. An empty string value means no error.
Error messages are formatted in a way that the first word is
an unique integer, followed by a human readable error
message from the second word. int(ERRNO) can be used to
acquire the error code, which then can be used as a
secondary output from the extension function. For example,
an awk program can use valueof() to determine if a global
symbol exists and is a function or a variable or anything
else.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="12%">


<p><b>LIBPATH</b></p></td>
<td width="3%"></td>
<td width="63%">


<p>is a semicolon separated list of search paths. When
loading an awk script by file name (-f command line argument
or include from another awk script) these paths are inserted
before the file name, in order, one by one, until the first
path that allows opening the file. An empty path is
equivalent to the current working directory. LIBPATH can be
modified from the command line using -v, as arguments are
scanned before loading the scripts. Setting LIBPATH to empty
string results in the original behaviour of mawk. LIBPATH is
ignored for script file names starting with slash
(&rsquo;/&rsquo;) as those are assumed to be absolute
paths.</p> </td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em"><b>8. Built-in
functions</b> <br>
String functions</p>

<p style="margin-left:22%;">gsub(<i>r,s,t</i>)
gsub(<i>r,s</i>)</p>

<p style="margin-left:32%;">Global substitution, every
match of regular expression <i>r</i> in variable <i>t</i> is
replaced by string <i>s</i>. The number of replacements is
returned. If <i>t</i> is omitted, <b>$0</b> is used. An
&amp; in the replacement string <i>s</i> is replaced by the
matched substring of <i>t</i>. \&amp; and \\ put literal
&amp; and \, respectively, in the replacement string.</p>

<p style="margin-left:22%;">index(<i>s,t</i>)</p>

<p style="margin-left:32%;">If <i>t</i> is a substring of
<i>s</i>, then the position where <i>t</i> starts is
returned, else 0 is returned. The first character of
<i>s</i> is in position 1.</p>

<p style="margin-left:22%;">length(<i>s</i>)</p>

<p style="margin-left:32%;">Returns the length of string
<i>s</i>.</p>

<p style="margin-left:22%;">match(<i>s,r</i>)</p>

<p style="margin-left:32%;">Returns the index of the first
longest match of regular expression <i>r</i> in string
<i>s</i>. Returns 0 if no match. As a side effect,
<b>RSTART</b> is set to the return value. <b>RLENGTH</b> is
set to the length of the match or &minus;1 if no match. If
the empty string is matched, <b>RLENGTH</b> is set to 0, and
1 is returned if the match is at the front, and
length(<i>s</i>)+1 is returned if the match is at the
back.</p>

<p style="margin-left:22%;">split(<i>s,A,r</i>)
split(<i>s,A</i>)</p>

<p style="margin-left:32%;">String <i>s</i> is split into
fields by regular expression <i>r</i> and the fields are
loaded into array <i>A</i>. The number of fields is
returned. See section 11 below for more detail. If <i>r</i>
is omitted, <b>FS</b> is used.</p>


<p style="margin-left:22%;">sprintf(<i>format,expr-list</i>)</p>

<p style="margin-left:32%;">Returns a string constructed
from <i>expr-list</i> according to <i>format</i>. See the
description of printf() below.</p>

<p style="margin-left:22%;">sub(<i>r,s,t</i>)
sub(<i>r,s</i>)</p>

<p style="margin-left:32%;">Single substitution, same as
gsub() except at most one substitution.</p>

<p style="margin-left:22%;">substr(<i>s,i,n</i>)
substr(<i>s,i</i>)</p>

<p style="margin-left:32%;">Returns the substring of string
<i>s</i>, starting at index <i>i</i>, of length <i>n</i>. If
<i>n</i> is omitted, the suffix of <i>s</i>, starting at
<i>i</i> is returned.</p>

<p style="margin-left:22%;">tolower(<i>s</i>)</p>

<p style="margin-left:32%;">Returns a copy of <i>s</i> with
all upper case characters converted to lower case.</p>

<p style="margin-left:22%;">toupper(<i>s</i>)</p>

<p style="margin-left:32%;">Returns a copy of <i>s</i> with
all lower case characters converted to upper case.</p>

<p style="margin-left:11%; margin-top: 1em">Arithmetic
functions</p>


<p style="margin-left:22%; margin-top: 1em">atan2(<i>y,x</i>)
Arctan of <i>y</i>/<i>x</i> between -PI and PI.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p>cos(<i>x</i>)</p></td>
<td width="8%"></td>
<td width="69%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="69%">


<p>Cosine function, <i>x</i> in radians.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p>exp(<i>x</i>)</p></td>
<td width="8%"></td>
<td width="69%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="69%">


<p>Exponential function.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p>int(<i>x</i>)</p></td>
<td width="8%"></td>
<td width="69%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="69%">


<p>Returns <i>x</i> truncated towards zero.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p>log(<i>x</i>)</p></td>
<td width="8%"></td>
<td width="69%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="69%">


<p>Natural logarithm.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p>rand()</p></td>
<td width="8%"></td>
<td width="69%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="69%">


<p>Returns a random number between zero and one.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p>sin(<i>x</i>)</p></td>
<td width="8%"></td>
<td width="69%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="69%">


<p>Sine function, <i>x</i> in radians.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">


<p>sqrt(<i>x</i>)</p></td>
<td width="8%"></td>
<td width="69%">
</td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="69%">


<p>Returns square root of <i>x</i>.</p></td></tr>
</table>

<p style="margin-left:22%;">srand(<i>expr</i>) srand()</p>

<p style="margin-left:32%;">Seeds the random number
generator, using the clock if <i>expr</i> is omitted, and
returns the value of the previous seed. <b>lmawk</b> seeds
the random number generator from the clock at startup so
there is no real need to call srand(). Srand(<i>expr</i>) is
useful for repeating pseudo random sequences.</p>

<p style="margin-left:11%; margin-top: 1em">Misc functions
(libmawk extensions)</p>


<p style="margin-left:22%;">call(<i>fname,arg1,arg2,...</i>)</p>

<p style="margin-left:32%;">Call awk function <i>fname</i>
with the supplied arguments. If the call fails, empty value,
else the return value of the callee is returned. Built-in
variable ERRNO is always set.</p>


<p style="margin-left:22%;">acall(<i>fname,arrname</i>)</p>

<p style="margin-left:32%;">Call awk function <i>fname</i>
with arguments supplied in array named <i>arrname</i> (both
arguments are strings naming an existing object). The array
should be indexed from 1. Number of arguments is determined
by looking for the first empty (non-existing) index in the
array. If the call fails, empty value, else the return value
of the callee is returned. Built-in variable ERRNO is always
set.</p>

<p style="margin-left:22%;">valueof(<i>vname
[,idx]</i>)</p>

<p style="margin-left:32%;">Return the value of variable
<i>fname</i>; if the variable is an array, return the
element indexed by <i>idx</i> (which must be present in this
case). If index is not present or is empty (&quot;&quot;),
the variable is expected to be scalar. Built-in variable
ERRNO is always set. NOTE: valueof() has access to the
global symbol table only. It will fail to resolve anything
else than global objects; most notably it will fail on local
variables, $ arguments and on most of the built-in
variables.</p>

<p style="margin-left:11%; margin-top: 1em"><b>9. Input and
output</b> <br>
There are two output statements, <b>print</b> and
<b>printf</b>.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="7%">


<p>print</p></td>
<td width="3%"></td>
<td width="53%">


<p>writes <b>$0 ORS</b> to standard output.</p></td>
<td width="15%">
</td></tr>
</table>

<p style="margin-left:22%;">print <i>expr</i>1,
<i>expr</i>2, ..., <i>expr</i>n</p>

<p style="margin-left:32%;">writes <i>expr</i>1 <b>OFS</b>
<i>expr</i>2 <b>OFS</b> ... <i>expr</i>n <b>ORS</b> to
standard output. Numeric expressions are converted to string
with <b>OFMT</b>.</p>

<p style="margin-left:22%;">printf <i>format,
expr-list</i></p>

<p style="margin-left:32%;">duplicates the printf C library
function writing to standard output. The complete ANSI C
format specifications are recognized with conversions %c,
%d, %e, %E, %f, %g, %G, %i, %o, %s, %u, %x, %X and %%, and
conversion qualifiers h and l.</p>

<p style="margin-left:11%; margin-top: 1em">The argument
list to print or printf can optionally be enclosed in
parentheses. Print formats numbers using <b>OFMT</b> or
&quot;%d&quot; for exact integers. &quot;%c&quot; with a
numeric argument prints the corresponding 8 bit character,
with a string argument it prints the first character of the
string. The output of print and printf can be redirected to
a file or command by appending &gt; <i>file</i>, &gt;&gt;
<i>file</i> or | <i>command</i> to the end of the print
statement. Redirection opens <i>file</i> or <i>command</i>
only once, subsequent redirections append to the already
open stream. By convention, <b>lmawk</b> associates the
filename &quot;/dev/stderr&quot; with stderr which allows
print and printf to be redirected to stderr. <b>lmawk</b>
also associates &quot;&minus;&quot; and
&quot;/dev/stdout&quot; with stdin and stdout which allows
these streams to be passed to functions. Opening /dev/fd/N
will do an fdopen() on file descriptor N, where N is an
integer - this is a libmawk extension. If any of the /dev
heuristics needs to be bypassed (i.e. the script wants to
open the real /dev/stdout or the real /dev/fd/5), the
leading slash should be doubled (e.g. //dev/fd/5).</p>

<p style="margin-left:11%; margin-top: 1em">The input
function <b>getline</b> has the following variations.</p>

<p style="margin-left:22%;">getline</p>

<p style="margin-left:32%;">reads into <b>$0</b>, updates
the fields, <b>NF</b>, <b>NR</b> and <b>FNR</b>.</p>

<p style="margin-left:22%;">getline &lt; <i>file</i></p>

<p style="margin-left:32%;">reads into <b>$0</b> from
<i>file</i>, updates the fields and <b>NF</b>.</p>

<p style="margin-left:22%;">getline <i>var</i></p>

<p style="margin-left:32%;">reads the next record into
<i>var</i>, updates <b>NR</b> and <b>FNR</b>.</p>

<p style="margin-left:22%;">getline <i>var</i> &lt;
<i>file</i></p>

<p style="margin-left:32%;">reads the next record of
<i>file</i> into <i>var</i>.</p>

<p style="margin-left:22%;"><i>command</i> | getline</p>

<p style="margin-left:32%;">pipes a record from
<i>command</i> into <b>$0</b> and updates the fields and
<b>NF</b>.</p>

<p style="margin-left:22%;"><i>command</i> | getline
<i>var</i></p>

<p style="margin-left:32%;">pipes a record from
<i>command</i> into <i>var</i>.</p>

<p style="margin-left:11%; margin-top: 1em">Getline returns
0 on end-of-file, &minus;1 on error, otherwise 1.</p>

<p style="margin-left:11%; margin-top: 1em">Commands on the
end of pipes are executed by /bin/sh.</p>

<p style="margin-left:11%; margin-top: 1em">The function
<b>close</b>(<i>expr</i>) closes the file or pipe associated
with <i>expr</i>. Close returns 0 if <i>expr</i> is an open
file, the exit status if <i>expr</i> is a piped command, and
&minus;1 otherwise. Close is used to reread a file or
command, make sure the other end of an output pipe is
finished or conserve file resources.</p>

<p style="margin-left:11%; margin-top: 1em">The function
<b>fflush</b>(<i>expr</i>) flushes the output file or pipe
associated with <i>expr</i>. Fflush returns 0 if <i>expr</i>
is an open output stream else &minus;1. Fflush without an
argument flushes stdout. Fflush with an empty argument
(&quot;&quot;) flushes all open output.</p>

<p style="margin-left:11%; margin-top: 1em">The function
<b>system</b>(<i>expr</i>) uses /bin/sh to execute
<i>expr</i> and returns the exit status of the command
<i>expr</i>. Changes made to the <b>ENVIRON</b> array are
not passed to commands executed with <b>system</b> or
pipes.</p>

<p style="margin-left:11%; margin-top: 1em"><b>10. User
defined functions</b> <br>
The syntax for a user defined function is</p>


<p style="margin-left:11%; margin-top: 1em"><b>function</b>
name( <i>args</i> ) { <i>statements</i> }</p>

<p style="margin-left:11%; margin-top: 1em">The function
body can contain a return statement</p>

<p style="margin-left:11%; margin-top: 1em"><b>return</b>
<i>opt_expr</i></p>

<p style="margin-left:11%; margin-top: 1em">A return
statement is not required. Function calls may be nested or
recursive. Functions are passed expressions by value and
arrays by reference. Extra arguments serve as local
variables and are initialized to <i>null</i>. For example,
csplit(<i>s,A</i>) puts each character of <i>s</i> into
array <i>A</i> and returns the length of <i>s</i>.</p>

<p style="margin-left:11%; margin-top: 1em">function
csplit(s, A, n, i)</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="85%">


<p>{</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="85%">


<p>n = length(s)</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="85%">


<p>for( i = 1 ; i &lt;= n ; i++ ) A[i] = substr(s, i,
1)</p> </td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="85%">


<p>return n</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="85%">


<p>}</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">Putting extra
space between passed arguments and local variables is
conventional. Functions can be referenced before they are
defined, but the function name and the &rsquo;(&rsquo; of
the arguments must touch to avoid confusion with
concatenation.</p>

<p style="margin-left:11%; margin-top: 1em"><b>11.
Splitting strings, records and files</b> <br>
Awk programs use the same algorithm to split strings into
arrays with split(), and records into fields on <b>FS</b>.
<b>lmawk</b> uses essentially the same algorithm to split
files into records on <b>RS</b>.</p>


<p style="margin-left:11%; margin-top: 1em">Split(<i>expr,A,sep</i>)
works as follows:</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="4%">


<p>(1)</p></td>
<td width="6%"></td>
<td width="68%">


<p>If <i>sep</i> is omitted, it is replaced by <b>FS</b>.
<i>Sep</i> can be an expression or regular expression. If it
is an expression of non-string type, it is converted to
string.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="4%">


<p>(2)</p></td>
<td width="6%"></td>
<td width="68%">


<p>If <i>sep</i> = &quot; &quot; (a single space), then
&lt;SPACE&gt; is trimmed from the front and back of
<i>expr</i>, and <i>sep</i> becomes &lt;SPACE&gt;.
<b>lmawk</b> defines &lt;SPACE&gt; as the regular expression
/[&nbsp;\t\n]+/. Otherwise <i>sep</i> is treated as a
regular expression, except that meta-characters are ignored
for a string of length 1, e.g., split(x, A, &quot;*&quot;)
and split(x, A, /\*/) are the same.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="4%">


<p>(3)</p></td>
<td width="6%"></td>
<td width="68%">


<p>If <i>expr</i> is not string, it is converted to string.
If <i>expr</i> is then the empty string &quot;&quot;,
split() returns 0 and <i>A</i> is set empty. Otherwise, all
non-overlapping, non-null and longest matches of <i>sep</i>
in <i>expr</i>, separate <i>expr</i> into fields which are
loaded into <i>A</i>. The fields are placed in A[1], A[2],
..., A[n] and split() returns n, the number of fields which
is the number of matches plus one. Data placed in <i>A</i>
that looks numeric is typed number and string.</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">Splitting
records into fields works the same except the pieces are
loaded into <b>$1</b>, <b>$2</b>,..., <b>$NF</b>. If
<b>$0</b> is empty, <b>NF</b> is set to 0 and all <b>$i</b>
to &quot;&quot;.</p>

<p style="margin-left:11%; margin-top: 1em"><b>lmawk</b>
splits files into records by the same algorithm, but with
the slight difference that <b>RS</b> is really a terminator
instead of a separator. (<b>ORS</b> is really a terminator
too).</p>

<p style="margin-left:22%; margin-top: 1em">E.g., if
<b>FS</b> = &quot;:+&quot; and <b>$0</b> = &quot;a::b:&quot;
, then <b>NF</b> = 3 and <b>$1</b> = &quot;a&quot;,
<b>$2</b> = &quot;b&quot; and <b>$3</b> = &quot;&quot;, but
if &quot;a::b:&quot; is the contents of an input file and
<b>RS</b> = &quot;:+&quot;, then there are two records
&quot;a&quot; and &quot;b&quot;.</p>

<p style="margin-left:11%; margin-top: 1em"><b>RS</b> =
&quot; &quot; is not special.</p>

<p style="margin-left:11%; margin-top: 1em">If <b>FS</b> =
&quot;&quot;, then <b>lmawk</b> breaks the record into
individual characters, and, similarly,
split(<i>s,A,</i>&quot;&quot;) places the individual
characters of <i>s</i> into <i>A</i>.</p>

<p style="margin-left:11%; margin-top: 1em"><b>12.
Multi-line records</b> <br>
Since <b>lmawk</b> interprets <b>RS</b> as a regular
expression, multi-line records are easy. Setting <b>RS</b> =
&quot;\n\n+&quot;, makes one or more blank lines separate
records. If <b>FS</b> = &quot; &quot; (the default), then
single newlines, by the rules for &lt;SPACE&gt; above,
become space and single newlines are field separators.</p>

<p style="margin-left:22%; margin-top: 1em">For example, if
a file is &quot;a&nbsp;b\nc\n\n&quot;, <b>RS</b> =
&quot;\n\n+&quot; and <b>FS</b> = &quot;&nbsp;&quot;, then
there is one record &quot;a&nbsp;b\nc&quot; with three
fields &quot;a&quot;, &quot;b&quot; and &quot;c&quot;.
Changing <b>FS</b> = &quot;\n&quot;, gives two fields
&quot;a b&quot; and &quot;c&quot;; changing <b>FS</b> =
&quot;&quot;, gives one field identical to the record.</p>

<p style="margin-left:11%; margin-top: 1em">If you want
lines with spaces or tabs to be considered blank, set
<b>RS</b> = &quot;\n([&nbsp;\t]*\n)+&quot;. For
compatibility with other awks, setting <b>RS</b> =
&quot;&quot; has the same effect as if blank lines are
stripped from the front and back of files and then records
are determined as if <b>RS</b> = &quot;\n\n+&quot;. Posix
requires that &quot;\n&quot; always separates records when
<b>RS</b> = &quot;&quot; regardless of the value of
<b>FS</b>. <b>lmawk</b> does not support this convention,
because defining &quot;\n&quot; as &lt;SPACE&gt; makes it
unnecessary.</p>

<p style="margin-left:11%; margin-top: 1em">Most of the
time when you change <b>RS</b> for multi-line records, you
will also want to change <b>ORS</b> to &quot;\n\n&quot; so
the record spacing is preserved on output.</p>

<p style="margin-left:11%; margin-top: 1em"><b>13. Program
execution</b> <br>
This section describes the order of program execution. First
<b>ARGC</b> is set to the total number of command line
arguments passed to the execution phase of the program.
<b>ARGV[0]</b> is set the name of the AWK interpreter and
<b>ARGV[1]</b> ... <b>ARGV[ARGC-1]</b> holds the remaining
command line arguments exclusive of options and program
source. For example with</p>

<p style="margin-left:11%; margin-top: 1em">lmawk &minus;f
prog v=1 A t=hello B</p>

<p style="margin-left:11%; margin-top: 1em"><b>ARGC</b> = 5
with <b>ARGV[0]</b> = &quot;lmawk&quot;, <b>ARGV[1]</b> =
&quot;v=1&quot;, <b>ARGV[2]</b> = &quot;A&quot;,
<b>ARGV[3]</b> = &quot;t=hello&quot; and <b>ARGV[4]</b> =
&quot;B&quot;.</p>

<p style="margin-left:11%; margin-top: 1em">Next, each
<b>BEGIN</b> block is executed in order. If the program
consists entirely of <b>BEGIN</b> blocks, then execution
terminates, else an input stream is opened and execution
continues. If <b>ARGC</b> equals 1, the input stream is set
to stdin, else the command line arguments <b>ARGV[1]</b> ...
<b>ARGV[ARGC-1]</b> are examined for a file argument.</p>

<p style="margin-left:11%; margin-top: 1em">The command
line arguments divide into three sets: file arguments,
assignment arguments and empty strings &quot;&quot;. An
assignment has the form <i>var</i>=<i>string</i>. When an
<b>ARGV[i]</b> is examined as a possible file argument, if
it is empty it is skipped; if it is an assignment argument,
the assignment to <i>var</i> takes place and <b>i</b> skips
to the next argument; else <b>ARGV[i]</b> is opened for
input. If it fails to open, execution terminates with exit
code 2. If no command line argument is a file argument, then
input comes from stdin. Getline in a <b>BEGIN</b> action
opens input. &quot;&minus;&quot; as a file argument denotes
stdin.</p>

<p style="margin-left:11%; margin-top: 1em">Once an input
stream is open, each input record is tested against each
<i>pattern</i>, and if it matches, the associated
<i>action</i> is executed. An expression pattern matches if
it is boolean true (see the end of section 2). A
<b>BEGIN</b> pattern matches before any input has been read,
and an <b>END</b> pattern matches after all input has been
read. A range pattern, <i>expr</i>1,<i>expr</i>2 , matches
every record between the match of <i>expr</i>1 and the match
<i>expr</i>2 inclusively.</p>

<p style="margin-left:11%; margin-top: 1em">When end of
file occurs on the input stream, the remaining command line
arguments are examined for a file argument, and if there is
one it is opened, else the <b>END</b> <i>pattern</i> is
considered matched and all <b>END</b> <i>actions</i> are
executed.</p>

<p style="margin-left:11%; margin-top: 1em">In the example,
the assignment v=1 takes place after the <b>BEGIN</b>
<i>actions</i> are executed, and the data placed in v is
typed number and string. Input is then read from file A. On
end of file A, t is set to the string &quot;hello&quot;, and
B is opened for input. On end of file B, the <b>END</b>
<i>actions</i> are executed.</p>

<p style="margin-left:11%; margin-top: 1em">Program flow at
the <i>pattern {action}</i> level can be changed with
the</p>


<p style="margin-left:11%; margin-top: 1em"><b>next</b></p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p><b>exit</b> <i>opt_expr</i></p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">statements. A
<b>next</b> statement causes the next input record to be
read and pattern testing to restart with the first
<i>pattern {action}</i> pair in the program. An <b>exit</b>
statement causes immediate execution of the <b>END</b>
actions or program termination if there are none or if the
<b>exit</b> occurs in an <b>END</b> action. The
<i>opt_expr</i> sets the exit value of the program unless
overridden by a later <b>exit</b> or subsequent error.</p>

<p style="margin-left:11%; margin-top: 1em"><b>14.
include</b> <br>
libmawk introduces source inclusion feature. Syntax is:</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>include &quot;filename&quot;</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">Include
statements must be on top level (outside of blocks). If file
name <br>
starts with a plus sign (&rsquo;+&rsquo;), the script file
is not loaded if it has <br>
been already loaded (by another include or -f command line
argument).</p>

<h2>EXAMPLES
<a name="EXAMPLES"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em">1. emulate
cat.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>{ print }</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">2. emulate
wc.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>{ chars += length($0) + 1 # add one for the \n</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>words += NF</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>}</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>END{ print NR, words, chars }</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">3. count the
number of unique &quot;real words&quot;.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>BEGIN { FS = &quot;[^A-Za-z]+&quot; }</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>{ for(i = 1 ; i &lt;= NF ; i++) word[$i] = &quot;&quot;
}</p> </td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>END { delete word[&quot;&quot;]</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>for ( i in word ) cnt++</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>print cnt</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>}</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">4. sum the
second field of every record based on the first field.</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>$1 ~ /credit|gain/ { sum += $2 }</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>$1 ~ /debit|loss/ { sum &minus;= $2 }</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>END { print sum }</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">5. sort a file,
comparing as string</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>{ line[NR] = $0 &quot;&quot; } # make sure of comparison
type</p> </td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">
</td>
<td width="8%">
</td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%">


<p># in case some lines look numeric</p></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>END { isort(line, NR)</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>for(i = 1 ; i &lt;= NR ; i++) print line[i]</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>}</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>#insertion sort of A[1..n]</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">


<p>function isort( A, n,</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">


<p>i, j, hold)</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>{</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>for( i = 2 ; i &lt;= n ; i++)</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>{</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>hold = A[j = i]</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>while ( A[j&minus;1] &gt; hold )</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>{ j&minus;&minus; ; A[j+1] = A[j] }</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>A[j] = hold</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>}</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p># sentinel A[0] = &quot;&quot; will be created if
needed</p> </td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>}</p></td>
<td width="8%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="46%">
</td></tr>
</table>

<h2>COMPATIBILITY ISSUES
<a name="COMPATIBILITY ISSUES"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em">The Posix
1003.2(draft 11.3) definition of the AWK language is AWK as
described in the AWK book with a few extensions that
appeared in SystemVR4 nawk. The extensions are:</p>

<p style="margin-left:22%; margin-top: 1em">New functions:
toupper() and tolower(); libmawk extensions: call(),
acall(), valueof().</p>

<p style="margin-left:22%; margin-top: 1em">New variables:
ENVIRON[] and CONVFMT; libmawk extension: ERRNO, LIBPATH. As
a libmawk extension, ENVIRON affects the environment of
children processes.</p>

<p style="margin-left:22%; margin-top: 1em">As a libmawk
extension, new built-in variable LIBPATH is used as a list
of search paths while loading scripts from the command line
or from include.</p>

<p style="margin-left:22%; margin-top: 1em">If a script
name starts with plus (&rsquo;+&rsquo;), the file is not
loaded if it has been loaded earlier (to avoid double
loading libs trough -f and/or include). This is a libmawk
extension.</p>

<p style="margin-left:22%; margin-top: 1em">It is possible
to include a script from another script using keyword
include &quot;scriptname.awk&quot; (libmawk extension).</p>

<p style="margin-left:22%; margin-top: 1em">ANSI C
conversion specifications for printf() and sprintf().</p>

<p style="margin-left:22%; margin-top: 1em">New command
options: &minus;v var=value, multiple -f options and
implementation options as arguments to &minus;W.</p>

<p style="margin-left:11%; margin-top: 1em">Posix AWK is
oriented to operate on files a line at a time. <b>RS</b> can
be changed from &quot;\n&quot; to another single character,
but it is hard to find any use for this &mdash; there are no
examples in the AWK book. By convention, <b>RS</b> =
&quot;&quot;, makes one or more blank lines separate
records, allowing multi-line records. When <b>RS</b> =
&quot;&quot;, &quot;\n&quot; is always a field separator
regardless of the value in <b>FS</b>.</p>

<p style="margin-left:11%; margin-top: 1em"><b>lmawk</b>,
on the other hand, allows <b>RS</b> to be a regular
expression. When &quot;\n&quot; appears in records, it is
treated as space, and <b>FS</b> always determines
fields.</p>

<p style="margin-left:11%; margin-top: 1em">Removing the
line at a time paradigm can make some programs simpler and
can often improve performance. For example, redoing example
3 from above,</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>BEGIN { RS = &quot;[^A-Za-z]+&quot; }</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>{ word[ $0 ] = &quot;&quot; }</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>END { delete word[ &quot;&quot; ]</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>for( i in word ) cnt++</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>print cnt</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>}</p></td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">counts the
number of unique words by making each word a record. On
moderate size files, <b>lmawk</b> executes twice as fast,
because of the simplified inner loop.</p>

<p style="margin-left:11%; margin-top: 1em">The following
program replaces each comment by a single space in a C
program file,</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>BEGIN {</p></td>
<td width="77%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>RS = &quot;/\*([^*]|\*+[^/*])*\*+/&quot;</p></td>
<td width="77%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%">
</td>
<td width="8%">
</td>
<td width="77%">


<p># comment is record separator</p></td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>ORS = &quot; &quot;</p></td>
<td width="77%">
</td></tr>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">


<p>getline hold</p></td>
<td width="77%">
</td></tr>
</table>

<p style="margin-left:11%;">}</p>

<p style="margin-left:11%; margin-top: 1em">{ print hold ;
hold = $0 }</p>

<p style="margin-left:11%; margin-top: 1em">END { printf
&quot;%s&quot; , hold }</p>

<p style="margin-left:11%; margin-top: 1em">Buffering one
record is needed to avoid terminating the last record with a
space.</p>

<p style="margin-left:11%; margin-top: 1em">With
<b>lmawk</b>, the following are all equivalent,</p>

<table width="100%" border="0" rules="none" frame="void"
       cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">


<p>x ~ /a\+b/ x ~ &quot;a\+b&quot; x ~
&quot;a\\+b&quot;</p> </td></tr>
</table>

<p style="margin-left:11%; margin-top: 1em">The strings get
scanned twice, once as string and once as regular
expression. On the string scan, <b>lmawk</b> ignores the
escape on non-escape characters while the AWK book advocates
<i>\c</i> be recognized as <i>c</i> which necessitates the
double escaping of meta-characters in strings. Posix
explicitly declines to define the behavior which passively
forces programs that must run under a variety of awks to use
the more portable but less readable, double escape.</p>

<p style="margin-left:11%; margin-top: 1em">Posix AWK does
not recognize &quot;/dev/std{out,err}&quot; or \x hex escape
sequences in strings. Unlike ANSI C, <b>lmawk</b> limits the
number of digits that follows \x to two as the current
implementation only supports 8 bit characters. The built-in
<b>fflush</b> first appeared in a recent (1993) AT&amp;T awk
released to netlib, and is not part of the posix standard.
Aggregate deletion with <b>delete</b> <i>array</i> is not
part of the posix standard.</p>

<p style="margin-left:11%; margin-top: 1em">Posix
explicitly leaves the behavior of <b>FS</b> = &quot;&quot;
undefined, and mentions splitting the record into characters
as a possible interpretation, but currently this use is not
portable across implementations.</p>

<p style="margin-left:11%; margin-top: 1em">Finally, here
is how <b>lmawk</b> handles exceptional cases not discussed
in the AWK book or the Posix draft. It is unsafe to assume
consistency across awks and safe to skip to the next
section.</p>

<p style="margin-left:22%; margin-top: 1em">substr(s, i, n)
returns the characters of s in the intersection of the
closed interval [1, length(s)] and the half-open interval
[i, i+n). When this intersection is empty, the empty string
is returned; so substr(&quot;ABC&quot;, 1, 0) = &quot;&quot;
and substr(&quot;ABC&quot;, &minus;4, 6) =
&quot;A&quot;.</p>

<p style="margin-left:22%; margin-top: 1em">Every string,
including the empty string, matches the empty string at the
front so, s ~ // and s ~ &quot;&quot;, are always 1 as is
match(s, //) and match(s, &quot;&quot;). The last two set
<b>RLENGTH</b> to 0.</p>

<p style="margin-left:22%; margin-top: 1em">index(s, t) is
always the same as match(s, t1) where t1 is the same as t
with metacharacters escaped. Hence consistency with match
requires that index(s, &quot;&quot;) always returns 1. Also
the condition, index(s,t) != 0 if and only t is a substring
of s, requires index(&quot;&quot;,&quot;&quot;) = 1.</p>

<p style="margin-left:22%; margin-top: 1em">If getline
encounters end of file, getline var, leaves var unchanged.
Similarly, on entry to the <b>END</b> actions, <b>$0</b>,
the fields and <b>NF</b> have their value unaltered from the
last record.</p>

<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>



<p style="margin-left:11%; margin-top: 1em"><i>egrep</i>(1),
<i>mawk</i>(1)</p>

<p style="margin-left:11%; margin-top: 1em">Aho, Kernighan
and Weinberger, <i>The AWK Programming Language</i>,
Addison-Wesley Publishing, 1988, (the AWK book), defines the
language, opening with a tutorial and advancing to many
interesting programs that delve into issues of software
design and analysis relevant to programming in any
language.</p>

<p style="margin-left:11%; margin-top: 1em"><i>The GAWK
Manual</i>, The Free Software Foundation, 1991, is a
tutorial and language reference that does not attempt the
depth of the AWK book and assumes the reader may be a novice
programmer. The section on AWK arrays is excellent. It also
discusses Posix requirements for AWK.</p>

<h2>BUGS
<a name="BUGS"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em"><b>lmawk</b>
cannot handle ascii NUL \0 in the source or data files. You
can output NUL using printf with %c, and any other 8 bit
character is acceptable input.</p>

<p style="margin-left:11%; margin-top: 1em"><b>lmawk</b>
implements printf() and sprintf() using the C library
functions, printf and sprintf, so full ANSI compatibility
requires an ANSI C library. In practice this means the h
conversion qualifier may not be available. Also <b>lmawk</b>
inherits any bugs or limitations of the library
functions.</p>

<p style="margin-left:11%; margin-top: 1em">Implementors of
the AWK language have shown a consistent lack of imagination
when naming their programs.</p>

<h2>AUTHOR
<a name="AUTHOR"></a>
</h2>


<p style="margin-left:11%; margin-top: 1em"><b>mawk:</b>
Mike Brennan (brennan@whidbey.com).</p>

<p style="margin-left:11%; margin-top: 1em"><b>libmawk
extensions:</b> Tibor Palinkas (libmawk@igor2.repo.hu).</p>
<hr>
</body>
</html>