Can field separator in awk encompass multiple characters?

后端 未结 5 1413
野的像风
野的像风 2020-12-31 07:05

Can I use a field separator consisting of multiple characters? Like I want to separate words which contain quotes and commas between them viz.

\"School\",\"College\"

5条回答
  •  耶瑟儿~
    2020-12-31 07:31

    Yes, you can use multiple characters for the -F argument because that value can be a regular expression. For example you can do things like:

    echo "hello:::my:::friend" | gawk -F':::' '{print $3}'
    

    which will return friend.

    The support for regexp as the argument to -F is true for nawk and gawk (GNU awk), the original awk does not support it. On Solaris this distinction is important, on Linux it is not important because awk is effectively a link to gawk. I would therefore say it is best practice to invoke awk as gawk because then it will work across platforms.

提交回复
热议问题