awk 的RS 为空,以什么为行分隔符?
时间:2011-06-21
来源:互联网
awk 的RS 为空,以什么为行分隔符?
看到有的文档说是以连续的换行为“行分隔符”;
有的说以整个内容为一行?
试了一下,好像不同的环境,处理是不同的?
看到有的文档说是以连续的换行为“行分隔符”;
有的说以整个内容为一行?
试了一下,好像不同的环境,处理是不同的?
作者: ljt2k 发布时间: 2011-06-21
没明白。
作者: zooyo 发布时间: 2011-06-21
回复 ljt2k
LZ意思RS="", 书上是这么说的,RS="", 就是以空白行为记录的分隔符,就是这么设计的,不解释。。
LZ意思RS="", 书上是这么说的,RS="", 就是以空白行为记录的分隔符,就是这么设计的,不解释。。
作者: liion631818 发布时间: 2011-06-21
:curse::curse::curse::curse::curse:
哈哈
哈哈
作者: jagel 发布时间: 2011-06-21
请看一下下面两种不同的说明:
RS
Input record separator (default is a new-line character). If the RS special variable is null, records are
separated by sequences of one or more blank lines; leading or trailing blank lines do not result in empty
records at the beginning or end of input; and the new-line character is always a field separator, regardless
of the value of the FS special variable.
Normally, AWK reads one line at a time, and breaks up the line into fields. You can set the "RS" variable to change AWK's definition of a "line." If you set it to an empty string, then AWK will read the entire file into memory. You can combine this with changing the "FS" variable.
RS
Input record separator (default is a new-line character). If the RS special variable is null, records are
separated by sequences of one or more blank lines; leading or trailing blank lines do not result in empty
records at the beginning or end of input; and the new-line character is always a field separator, regardless
of the value of the FS special variable.
Normally, AWK reads one line at a time, and breaks up the line into fields. You can set the "RS" variable to change AWK's definition of a "line." If you set it to an empty string, then AWK will read the entire file into memory. You can combine this with changing the "FS" variable.
作者: ljt2k 发布时间: 2011-06-21
本帖最后由 liion631818 于 2011-06-21 11:00 编辑
第一点:
当RS=""时, 开始和结尾的空白行会被忽略掉,就跟FS为默认值时,行开头和结尾的空白字符被忽略一样,
and the new-line character is always a field separator
这句话的意思是换行符是域分隔符,而且只是是其中之一,应该在并上设置的FS的值,例如
复制代码
此时,空白,tab和换行都是域分隔符
同理,可以理解:
复制代码
第二点:
个人感觉 AWK will read the entire file into memory应该包含一个假设条件,就是整个文件除了开头和结尾没有空白行
第一点:
当RS=""时, 开始和结尾的空白行会被忽略掉,就跟FS为默认值时,行开头和结尾的空白字符被忽略一样,
and the new-line character is always a field separator
这句话的意思是换行符是域分隔符,而且只是是其中之一,应该在并上设置的FS的值,例如
- cat file
- 1 xx
- 2 xx
- 3
- 4
- awk -vRS="" '{print $1, $2, $3}' file
- 1 xx 2
同理,可以理解:
- $ cat file
- 1#xx
- 2#xx
- 3
- 4
- awk -vRS="" -vFS="#" '{print $1, $2, $3}' file
- 1 xx 2
个人感觉 AWK will read the entire file into memory应该包含一个假设条件,就是整个文件除了开头和结尾没有空白行
作者: liion631818 发布时间: 2011-06-21
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28