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

后端 未结 2 1094
北海茫月
北海茫月 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:33

    Try this instead:

    grep -G $'\t'
    

    For more info please see bug #23535: Grep Doesn't Support \t as a tab character.

    0 讨论(0)
  • 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\}'
    
    0 讨论(0)
提交回复
热议问题