summaryrefslogtreecommitdiff
blob: d21fdfbf61a1ba3291257b5ee92c5877f1e57293 (plain)
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
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2011-09-05 14:11+0600\n"
"PO-Revision-Date: 2010-10-22 00:23+0600\n"
"Last-Translator: Automatically generated\n"
"Language-Team: none\n"
"Language: el\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):6
msgid "Awk by example, Part 2"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(author:title):8
msgid "Author"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(mail:link):9
msgid "drobbins@gentoo.org"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(mail):9
msgid "Daniel Robbins"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(abstract):12
msgid ""
"In this sequel to his previous intro to awk, Daniel Robbins continues to "
"explore awk, a great language with a strange name. Daniel will show you how "
"to handle multi-line records, use looping constructs, and create and use awk "
"arrays. By the end of this article, you'll be well versed in a wide range of "
"awk features, and you'll be ready to write your own powerful awk scripts."
msgstr ""

#. The original version of this article was published on IBM developerWorks,
#. and is property of Westtech Information Services. This document is an updated
#. version of the original article, and contains various improvements made by the
#. Gentoo Linux Documentation team
#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(version):25
msgid "1.4"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(date):26
msgid "2005-10-31"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):29
msgid "Records, loops, and arrays"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):31
msgid "Multi-line records"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):34
msgid ""
"Awk is an excellent tool for reading in and processing structured data, such "
"as the system's <path>/etc/passwd</path> file. <path>/etc/passwd</path> is "
"the UNIX user database, and is a colon-delimited text file, containing a lot "
"of important information, including all existing user accounts and user IDs, "
"among other things. In <uri link=\"/doc/en/articles/l-awk1.xml\">my previous "
"article</uri>, I showed you how awk could easily parse this file. All we had "
"to do was to set the FS (field separator) variable to \":\"."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):44
msgid ""
"By setting the FS variable correctly, awk can be configured to parse almost "
"any kind of structured data, as long as there is one record per line. "
"However, just setting FS won't do us any good if we want to parse a record "
"that exists over multiple lines. In these situations, we also need to modify "
"the RS record separator variable. The RS variable tells awk when the current "
"record ends and a new record begins."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):53
msgid ""
"As an example, let's look at how we'd handle the task of processing an "
"address list of Federal Witness Protection Program participants:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):58
msgid "Sample entry from Federal Witness Protection Program participants list"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):58
#, no-wrap
msgid ""
"\n"
"Jimmy the Weasel\n"
"100 Pleasant Drive\n"
"San Francisco, CA 12345\n"
"\n"
"Big Tony\n"
"200 Incognito Ave.\n"
"Suburbia, WA 67890\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):68
msgid ""
"Ideally, we'd like awk to recognize each 3-line address as an individual "
"record, rather than as three separate records. It would make our code a lot "
"simpler if awk would recognize the first line of the address as the first "
"field ($1), the street address as the second field ($2), and the city, "
"state, and zip code as field $3. The following code will do just what we "
"want:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):76
msgid "Making one field from the address"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):76
#, no-wrap
msgid ""
"\n"
"BEGIN {\n"
"    FS=\"\\n\"\n"
"    RS=\"\"\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):83
msgid ""
"Above, setting FS to \"\\n\" tells awk that each field appears on its own "
"line. By setting RS to \"\", we also tell awk that each address record is "
"separated by a blank line. Once awk knows how the input is formatted, it can "
"do all the parsing work for us, and the rest of the script is simple. Let's "
"look at a complete script that will parse this address list and print out "
"each address record on a single line, separating each field with a comma."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):92
msgid "Complete script"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):92
#, no-wrap
msgid ""
"\n"
"BEGIN {\n"
"    FS=\"\\n\"\n"
"    RS=\"\"\n"
"}\n"
"{ print $1 \", \" $2 \", \" $3 }\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):101
msgid ""
"If this script is saved as <path>address.awk</path>, and the address data is "
"stored in a file called <path>address.txt</path>, you can execute this "
"script by typing <c>awk -f address.awk address.txt</c>. This code produces "
"the following output:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):108
msgid "The script's output"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):108
#, no-wrap
msgid ""
"\n"
"Jimmy the Weasel, 100 Pleasant Drive, San Francisco, CA 12345\n"
"Big Tony, 200 Incognito Ave., Suburbia, WA 67890\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):116
msgid "OFS and ORS"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):119
msgid ""
"In address.awk's print statement, you can see that awk concatenates (joins) "
"strings that are placed next to each other on a line. We used this feature "
"to insert a comma and a space (\", \") between the three address fields that "
"appeared on the line. While this method works, it's a bit ugly looking. "
"Rather than inserting literal \", \" strings between our fields, we can have "
"awk do it for us by setting a special awk variable called OFS. Take a look "
"at this code snippet."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):128
msgid "Sample code snippet"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):128
#, no-wrap
msgid ""
"\n"
"print \"Hello\", \"there\", \"Jim!\"\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):132
msgid ""
"The commas on this line are not part of the actual literal strings. Instead, "
"they tell awk that \"Hello\", \"there\", and \"Jim!\" are separate fields, "
"and that the OFS variable should be printed between each string. By default, "
"awk produces the following output:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):139
msgid "Output produced by awk"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):139
#, no-wrap
msgid ""
"\n"
"Hello there Jim!\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):143
msgid ""
"This shows us that by default, OFS is set to \" \", a single space. However, "
"we can easily redefine OFS so that awk will insert our favorite field "
"separator. Here's a revised version of our original <path>address.awk</path> "
"program that uses OFS to output those intermediate \", \" strings:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):150
msgid "Redefining OFS"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):150
#, no-wrap
msgid ""
"\n"
"BEGIN {\n"
"    FS=\"\\n\"\n"
"    RS=\"\"\n"
"    OFS=\", \"\n"
"}\n"
"{ print $1, $2, $3 }\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):159
msgid ""
"Awk also has a special variable called ORS, called the \"output record "
"separator\". By setting ORS, which defaults to a newline (\"\\n\"), we can "
"control the character that's automatically printed at the end of a print "
"statement. The default ORS value causes awk to output each new print "
"statement on a new line. If we wanted to make the output double-spaced, we "
"would set ORS to \"\\n\\n\". Or, if we wanted records to be separated by a "
"single space (and no newline), we would set ORS to \" \"."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):172
msgid "Multi-line to tabbed"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):175
msgid ""
"Let's say that we wrote a script that converted our address list to a single-"
"line per record, tab-delimited format for import into a spreadsheet. After "
"using a slightly modified version of <path>address.awk</path>, it would "
"become clear that our program only works for three-line addresses. If awk "
"encountered the following address, the fourth line would be thrown away and "
"not printed:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):184
msgid "Sample entry"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):184
#, no-wrap
msgid ""
"\n"
"Cousin Vinnie\n"
"Vinnie's Auto Shop\n"
"300 City Alley\n"
"Sosueme, OR 76543\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):191
msgid ""
"To handle situations like this, it would be good if our code took the number "
"of records per field into account, printing each one in order. Right now, "
"the code only prints the first three fields of the address. Here's some code "
"that does what we want:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):198
msgid "Improved code"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):198
#, no-wrap
msgid ""
"\n"
"BEGIN { \n"
"    FS=\"\\n\" \n"
"    RS=\"\" \n"
"    ORS=\"\" \n"
"} \n"
" \n"
"{  \n"
"    x=1 \n"
"    while ( x&lt;NF ) { \n"
"        print $x \"\\t\" \n"
"        x++ \n"
"    } \n"
"    print $NF \"\\n\" \n"
"} \n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):215
msgid ""
"First, we set the field separator FS to \"\\n\" and the record separator RS "
"to \"\" so that awk parses the multi-line addresses correctly, as before. "
"Then, we set the output record separator ORS to \"\", which will cause the "
"print statement to not output a newline at the end of each call. This means "
"that if we want any text to start on a new line, we need to explicitly write "
"print \"\\n\"."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):223
msgid ""
"In the main code block, we create a variable called x that holds the number "
"of current field that we're processing. Initially, it's set to 1. Then, we "
"use a while loop (an awk looping construct identical to that found in the C "
"language) to iterate through all but the last record, printing the record "
"and a tab character. Finally, we print the last record and a literal "
"newline; again, since ORS is set to \"\", print won't output newlines for "
"us. Program output looks like this, which is exactly what we wanted:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):233
msgid ""
"Our intended output. Not pretty, but tab delimited for easy import into a "
"spreadsheet"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):233
#, no-wrap
msgid ""
"\n"
"Jimmy the Weasel        100 Pleasant Drive      San Francisco, CA 12345 \n"
"Big Tony        200 Incognito Ave.      Suburbia, WA 67890\n"
"Cousin Vinnie   Vinnie's Auto Shop      300 City Alley  Sosueme, OR 76543\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):242
msgid "Looping constructs"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):245
msgid ""
"We've already seen awk's while loop construct, which is identical to its C "
"counterpart. Awk also has a \"do...while\" loop that evaluates the condition "
"at the end of the code block, rather than at the beginning like a standard "
"while loop. It's similar to \"repeat...until\" loops that can be found in "
"other languages. Here's an example:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):253
msgid "do...while example"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):253
#, no-wrap
msgid ""
"\n"
"{\n"
"    count=1\n"
"    do {\n"
"        print \"I get printed at least once no matter what\" \n"
"    } while ( count != 1 )\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):262
msgid ""
"Because the condition is evaluated after the code block, a \"do...while\" "
"loop, unlike a normal while loop, will always execute at least once. On the "
"other hand, a normal while loop will never execute if its condition is false "
"when the loop is first encountered."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):272
msgid "for loops"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):275
msgid ""
"Awk allows you to create for loops, which like while loops are identical to "
"their C counterpart:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):280
msgid "Example loop"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):280
#, no-wrap
msgid ""
"\n"
"for ( initial assignment; comparison; increment ) {\n"
"    code block\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):286
msgid "Here's a quick example:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):290
msgid "Quick example"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):290
#, no-wrap
msgid ""
"\n"
"for ( x = 1; x &lt;= 4; x++ ) {\n"
"    print \"iteration\",x\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):296
msgid "This snippet will print:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):300
msgid "Output of the above snippet"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):300
#, no-wrap
msgid ""
"\n"
"iteration 1\n"
"iteration 2\n"
"iteration 3\n"
"iteration 4\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):310
msgid "Break and continue"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):313
msgid ""
"Again, just like C, awk provides break and continue statements. These "
"statements provide better control over awk's various looping constructs. "
"Here's a code snippet that desperately needs a break statement:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):319
msgid "Code snippet needing a break statement"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):319
#, no-wrap
msgid ""
"\n"
"while (1) {\n"
"    print \"forever and ever...\"\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):325
msgid ""
"Because 1 is always true, this while loop runs forever. Here's a loop that "
"only executes ten times:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):330
msgid "Loop that executes only 10 times"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):330
#, no-wrap
msgid ""
"\n"
"x=1\n"
"while(1) {\n"
"    print \"iteration\",x\n"
"    if ( x == 10 ) {\n"
"        break\n"
"    }\n"
"    x++\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):341
msgid ""
"Here, the break statement is used to \"break out\" of the innermost loop. "
"\"break\" causes the loop to immediately terminate and execution to continue "
"at the line after the loop's code block."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):347
msgid "The continue statement complements break, and works like this:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):351
msgid "The continues statement complementing break"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):351
#, no-wrap
msgid ""
"\n"
"x=1\n"
"while (1) {\n"
"    if ( x == 4 ) {\n"
"        x++\n"
"        continue\n"
"    }\n"
"    print \"iteration\",x\n"
"    if ( x &gt; 20 ) {\n"
"        break\n"
"    }\n"
"    x++\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):366
msgid ""
"This code will print \"iteration 1\" through \"iteration 21\", except for "
"\"iteration 4\". If iteration equals 4, x is incremented and the continue "
"statement is called, which immediately causes awk to start to the next loop "
"iteration without executing the rest of the code block. The continue "
"statement works for every kind of awk iterative loop, just as break does. "
"When used in the body of a for loop, continue will cause the loop control "
"variable to be automatically incremented. Here's an equivalent for loop:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):376
msgid "Equivalent for loop"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):376
#, no-wrap
msgid ""
"\n"
"for ( x=1; x&lt;=21; x++ ) {\n"
"    if ( x == 4 ) {\n"
"        continue\n"
"    }\n"
"    print \"iteration\",x\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):385
msgid ""
"It wasn't necessary to increment x just before calling continue as it was in "
"our while loop, since the for loop increments x automatically."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):393
msgid "Arrays"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):396
msgid ""
"You'll be pleased to know that awk has arrays. However, under awk, it's "
"customary to start array indices at 1, rather than 0:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):401
msgid "Sample awk arrays"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):401
#, no-wrap
msgid ""
"\n"
"myarray[1]=\"jim\"\n"
"myarray[2]=456\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):406
msgid ""
"When awk encounters the first assignment, myarray is created and the element "
"myarray[1] is set to \"jim\". After the second assignment is evaluated, the "
"array has two elements."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):412
msgid ""
"Once defined, awk has a handy mechanism to iterate over the elements of an "
"array, as follows:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):417
msgid "Iterating over arrays"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):417
#, no-wrap
msgid ""
"\n"
"for ( x in myarray ) {\n"
"    print myarray[x]\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):423
msgid ""
"This code will print out every element in the array myarray. When you use "
"this special \"in\" form of a for loop, awk will assign every existing index "
"of myarray to x (the loop control variable) in turn, executing the loop's "
"code block once after each assignment. While this is a very handy awk "
"feature, it does have one drawback -- when awk cycles through the array "
"indices, it doesn't follow any particular order. That means that there's no "
"way for us to know whether the output of above code will be:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):433
msgid "Output of above code"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):433
#, no-wrap
msgid ""
"\n"
"jim\n"
"456\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):438
msgid "or"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):442
msgid "Other output of above code"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):442
#, no-wrap
msgid ""
"\n"
"456\n"
"jim\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):447
msgid ""
"To loosely paraphrase Forrest Gump, iterating over the contents of an array "
"is like a box of chocolates -- you never know what you're going to get. This "
"has something to do with the \"stringiness\" of awk arrays, which we'll now "
"take a look at."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):457
msgid "Array index stringiness"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):460
msgid ""
"<uri link=\"/doc/en/articles/l-awk1.xml\">In my previous article</uri>, I "
"showed you that awk actually stores numeric values in a string format. While "
"awk performs the necessary conversions to make this work, it does open the "
"door for some odd-looking code:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):467
msgid "Odd looking code"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):467
#, no-wrap
msgid ""
"\n"
"a=\"1\"\n"
"b=\"2\"\n"
"c=a+b+3\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):473
msgid ""
"After this code executes, c is equal to 6. Since awk is \"stringy\", adding "
"strings \"1\" and \"2\" is functionally no different than adding the numbers "
"1 and 2. In both cases, awk will successfully perform the math. Awk's "
"\"stringy\" nature is pretty intriguing -- you may wonder what happens if we "
"use string indexes for arrays. For instance, take the following code:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):481
msgid "Sample code"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):481
#, no-wrap
msgid ""
"\n"
"myarr[\"1\"]=\"Mr. Whipple\"\n"
"print myarr[\"1\"]\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):486
msgid ""
"As you might expect, this code will print \"Mr. Whipple\". But how about if "
"we drop the quotes around the second \"1\" index?"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):491
msgid "Dropping the qoutes code"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):491
#, no-wrap
msgid ""
"\n"
"myarr[\"1\"]=\"Mr. Whipple\"\n"
"print myarr[1]\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):497
msgid ""
"Guessing the result of this code snippet is a bit more difficult. Does awk "
"consider myarr[\"1\"] and myarr[1] to be two separate elements of the array, "
"or do they refer to the same element? The answer is that they refer to the "
"same element, and awk will print \"Mr. Whipple\", just as in the first code "
"snippet. Although it may seem strange, behind the scenes awk has been using "
"string indexes for its arrays all this time!"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):506
msgid ""
"After learning this strange fact, some of us may be tempted to execute some "
"wacky code that looks like this:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):511
msgid "Wacky code"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):511
#, no-wrap
msgid ""
"\n"
"myarr[\"name\"]=\"Mr. Whipple\"\n"
"print myarr[\"name\"]\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):516
msgid ""
"Not only does this code not raise an error, but it's functionally identical "
"to our previous examples, and will print \"Mr. Whipple\" just as before! As "
"you can see, awk doesn't limit us to using pure integer indexes; we can use "
"string indexes if we want to, without creating any problems. Whenever we use "
"non-integer array indices like myarr[\"name\"], we're using associative "
"arrays. Technically, awk isn't doing anything different behind the scenes "
"than when we use a string index (since even if you use an \"integer\" index, "
"awk still treats it as a string). However, you should still call 'em "
"associative arrays -- it sounds cool and will impress your boss. The stringy "
"index thing will be our little secret. ;)"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):532
msgid "Array tools"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):535
msgid ""
"When it comes to arrays, awk gives us a lot of flexibility. We can use "
"string indexes, and we aren't required to have a continuous numeric sequence "
"of indices (for example, we can define myarr[1] and myarr[1000], but leave "
"all other elements undefined). While all this can be very helpful, in some "
"circumstances it can create confusion. Fortunately, awk offers a couple of "
"handy features to help make arrays more manageable."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):544
msgid ""
"First, we can delete array elements. If you want to delete element 1 of your "
"array fooarray, type:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):549
msgid "Deleting array elements"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):549
#, no-wrap
msgid ""
"\n"
"delete fooarray[1]\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):553
msgid ""
"And, if you want to see if a particular array element exists, you can use "
"the special \"in\" boolean operator as follows:"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre:caption):558
msgid "Checking if a particular array element exists"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(pre):558
#, no-wrap
msgid ""
"\n"
"if ( 1 in fooarray ) {\n"
"    print \"Ayep!  It's there.\"\n"
"} else {\n"
"    print \"Nope!  Can't find it.\"\n"
"}\n"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):569
msgid "Next time"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(p):572
msgid ""
"We've covered a lot of ground in this article. Next time, I'll round out "
"your awk knowledge by showing you how to use awk's math and string functions "
"and how to create your own functions. I'll also walk you through the "
"creation of a checkbook balancing program. Until then, I encourage you to "
"write some of your own awk programs, and to check out the following "
"resources."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(title):585
msgid "Resources"
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(li):590
msgid ""
"Read Daniel's other awk articles on developerWorks: Common threads: Awk by "
"example, <uri link=\"l-awk1.xml\">Part 1</uri> and <uri link=\"l-awk3.xml"
"\">Part 3</uri>."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(li):595
msgid ""
"If you'd like a good old-fashioned book, O'Reilly's <uri link=\"http://www."
"oreilly.com/catalog/sed2/\">sed &amp; awk, 2nd Edition</uri> is a wonderful "
"choice."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(li):600
msgid ""
"Be sure to check out the <uri link=\"http://www.faqs.org/faqs/computer-lang/"
"awk/faq/\">comp.lang.awk FAQ</uri>. It also contains lots of additional awk "
"links."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(li):605
msgid ""
"Patrick Hartigan's <uri link=\"http://sparky.rice.edu/~hartigan/awk.html"
"\">awk tutorial</uri> is packed with handy awk scripts."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(li):609
msgid ""
"<uri link=\"http://www.tasoft.com/tawk.html\">Thompson's TAWK Compiler</uri> "
"compiles awk scripts into fast binary executables. Versions are available "
"for Windows, OS/2, DOS, and UNIX."
msgstr ""

#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(li):614
msgid ""
"<uri link=\"http://www.gnu.org/software/gawk/manual/gawk.html\">The GNU Awk "
"User's Guide</uri> is available for online reference."
msgstr ""

#. Place here names of translator, one per line. Format should be NAME; ROLE; E-MAIL
#: ../../gentoo/xml/htdocs/doc/en/articles/l-awk2.xml(None):0
msgid "translator-credits"
msgstr ""