Search for tabs, without -P, using 'grep'

后端 未结 2 1096
北海茫月
北海茫月 2021-01-11 19:20

I used to use grep -P successfully earlier, till I got a machine where grep is not compiled with Perl regular expression support. Now I am having trouble matchi

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 19:37

    The Perl-RegEx understand '[\t]', so you can do like this:

    echo -e "\t : words" | grep -P '^[\t]'
    

    the basic-regexp and extended-regexp need for these a "blank" (RegEx for "Space" / "Tab"):

    echo -e "\t : words" | grep -G '^[[:blank:]]'
    echo -e "\t : words" | grep -E '^[[:blank:]]'
    

    maybe you can use it this way:

    echo -e "\t : words" | grep -E '^[[:blank:]]{2,8}'
    echo -e "\t : words" | grep -G '^[[:blank:]]\{2,8\}'
    

提交回复
热议问题