- 论坛徽章:
- 16
|
本帖最后由 expert1 于 2014-04-29 18:05 编辑
回复 1# ly5066113
多谢tim的大作,不过根据官方手册,有个地方要改一下,
{code}
如果RS被设置为空,那么awk会将连续的空行作为行分隔符,与RS设置成"\n\n+"有什么区别???
1、忽略文件开头和结尾的空行。且文件不以记录分隔符结束,即最后不是空行,会将最后一个记录的尾\n去掉
2、不设置RT变量(测试未发现规律,暂时认为RT变量不可用)
{/code}
RT不可用,严格说应该是匹配为空。
这是官方手册
The following table summarizes how records are split, based on the value of RS:
RS == "\n"
Records are separated by the newline character (‘\n’). In effect, every line in the data file is a separate record, including blank lines. This is the default.
RS == any single character
Records are separated by each occurrence of the character. Multiple successive occurrences delimit empty records.
RS == ""
Records are separated by runs of blank lines. When FS is a single character, then the newline character always serves as a field separator, in addition to whatever value FS may have. Leading and trailing newlines in a file are ignored.
RS == regexp
Records are separated by occurrences of characters that match regexp. Leading and trailing matches of regexp delimit empty records. (This is a gawk extension; it is not specified by the POSIX standard.)
In all cases, gawk sets RT to the input text that matched the value specified by RS. But if the input file ended without any text that matches RS, then gawk sets RT to the null string.
|
|