How to use word boundaries in awk without using match() function?

前端 未结 3 1865
太阳男子
太阳男子 2021-01-14 17:42

I want to add word boundaries to this awk command:

awk \'{$0=tolower($0)};/wordA/&&/wordB/ { print FILENAME \":\" $0; }\' myfile.txt
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 18:32

    You want to use gawk instead of awk:

    gawk '{$0=tolower($0)};/\ywordA\y/&&/\ywordB\y/ { print FILENAME ":" $0; }' myfile.txt
    

    will do what you want, if your system has gawk (e.g. on Mac OS X). \y is a GNU extension to awk.

提交回复
热议问题