Does awk CR LF handling break on cygwin?

前端 未结 2 2110

On Linux, this runs as expected:

$ echo -e \"line1\\r\\nline2\"|awk -v RS=\"\\r\\n\" \'/^line/ {print \"awk: \"$0}\'
awk: line1
awk: line2

2条回答
  •  死守一世寂寞
    2020-12-17 20:23

    I just checked with Arnold Robbins (the provider of gawk) and the answer is that it's something done by the C libraries and to stop it happening you should set the awk BINMODE variable to 3:

    $ echo -e "line1\r\nline2" | awk '1' | cat -v
    line1
    line2
    
    $ echo -e "line1\r\nline2" | awk -v BINMODE=3 '1' | cat -v
    line1^M
    line2
    

    See the man page for more info if interested.

提交回复
热议问题