How to set the field separator to an empty string?

懵懂的女人 提交于 2019-11-29 15:16:51

Looks like you can do this:

$ awk -F '' '{print $2}' <<< "abc"
b

Tested on GNU awk (versions 3.0.4 and 4.1.1) and mawk version 1.2

To be clear, the space between -F and '' is important!

Why? Is this because setting FS to empty is a gawk specific?

Note that the standards say that the results are unspecified if an empty string is assigned to FS. Some versions of awk will produce the output you showed above in your example. The version of awk on OS/X issues the warning and output.

awk: field separator FS is empty

So the special meaning of setting FS to an empty string, does not work in every awk.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!