课程: AWK Essential Training

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Specifying field and record separators with variables

Specifying field and record separators with variables - Linux教程

课程: AWK Essential Training

Specifying field and record separators with variables

- [Instructor] In addition to specifying the field separator on the command line, you can also specify it within an awk program. This is done by assigning a value to the special variable FS. For example, this sets the field separator to a comma. Note that the name FS is in all caps and the value that you assign to it must be enclosed in quotes to make sure awk understands that it's a string. Now this assigns a comma to the FS variable. However, this program, print dollar two, does not actually work the way that you would expect. It prints nothing, but the second line prints the second value on the line, which is five. So what happened here? First off, I'd like to point out the use of the semicolon in the program. As in C and many other programming languages, the semicolon marks the end of one statement and the beginning of the next, and each statement is executed in order. So this action, FS equals comma, semicolon…

内容