Grep for beginning and end of line?

后端 未结 6 1217
-上瘾入骨i
-上瘾入骨i 2020-12-04 20:50

I have a file where I want to grep for lines that start with either -rwx or drwx AND end in any number.

I\'ve got this, but it isnt quite right. Any ideas?

6条回答
  •  佛祖请我去吃肉
    2020-12-04 21:43

    The tricky part is a regex that includes a dash as one of the valid characters in a character class. The dash has to come immediately after the start for a (normal) character class and immediately after the caret for a negated character class. If you need a close square bracket too, then you need the close square bracket followed by the dash. Mercifully, you only need dash, hence the notation chosen.

    grep '^[-d]rwx.*[0-9]$' "$@"
    

    See: Regular Expressions and grep for POSIX-standard details.

提交回复
热议问题