Grep for beginning and end of line?

后端 未结 6 1208
-上瘾入骨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:39

    It should be noted that not only will the caret (^) behave differently within the brackets, it will have the opposite result of placing it outside of the brackets. Placing the caret where you have it will search for all strings NOT beginning with the content you placed within the brackets. You also would want to place a period before the asterisk in between your brackets as with grep, it also acts as a "wildcard".

    grep ^[.rwx].*[0-9]$
    

    This should work for you, I noticed that some posters used a character class in their expressions which is an effective method as well, but you were not using any in your original expression so I am trying to get one as close to yours as possible explaining every minor change along the way so that it is better understood. How can we learn otherwise?

提交回复
热议问题