Grep for beginning and end of line?

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

    are you parsing output of ls -l?

    If you are, and you just want to get the file name

    find . -iname "*[0-9]" 
    

    If you have no choice because usrLog.txt is created by something/someone else and you absolutely must use this file, other options include

    awk '/^[-d].*[0-9]$/' file
    

    Ruby(1.9+)

    ruby -ne 'print if /^[-d].*[0-9]$/' file
    

    Bash

    while read -r line ; do  case $line in [-d]*[0-9] ) echo $line;  esac; done < file
    

提交回复
热议问题