21.07.2015 Views

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

GAWK: Effective AWK Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3: Reading Input Files 45⊣ -->AAxxBxxC gawk-3.1.6 -F ’(^x+)|( +)’ ’{ for (i = 1; i AABxxC {> for (i = 1; i print "Field", i, "is", $i> }’⊣ Field 1 is a⊣ Field 2 is⊣ Field 3 is bTraditionally, the behavior of FS equal to "" was not defined. In this case, most versionsof Unix awk simply treat the entire record as only having one field. In compatibility mode(see Section 11.2 [Command-Line Options], page 177), if FS is the null string, then gawkalso behaves this way.3.5.3 Setting FS from the Command LineFS can be set on the command line. Use the ‘-F’ option to do so. For example:awk -F, ’program’ input-filessets FS to the ‘,’ character. Notice that the option uses an uppercase ‘F’ instead of alowercase ‘f’. The latter option (‘-f’) specifies a file containing an awk program. Case issignificant in command-line options: the ‘-F’ and ‘-f’ options have nothing to do with eachother. You can use both options at the same time to set the FS variable and get an awkprogram from a file.The value used for the argument to ‘-F’ is processed in exactly the same way as assignmentsto the built-in variable FS. Any special characters in the field separator must beescaped appropriately. For example, to use a ‘\’ as the field separator on the commandline, you would have to type:# same as FS = "\\"awk -F\\\\ ’...’ files ...

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!