awk: fatal: Invalid regular expression when setting multiple field separators

后端 未结 3 1076
耶瑟儿~
耶瑟儿~ 2021-01-07 12:42

I was trying to solve Grep regex to select only 10 character using awk. The question consists in a string XXXXXX[YYYYY--ZZZZZ and the OP wants to p

3条回答
  •  滥情空心
    2021-01-07 13:10

    You need to use double backslash for escaping regex meta chars inside double quoted string so that it would be treated as regex meta character otherwise (if you use single backslash) it would be treated as ecape sequence.

    $ echo 'XXXXXXX[YYYYYbbZZZZ' | awk -v FS="bb|\\[" '{print $2}'
    YYYYY
    

提交回复
热议问题