Search code examples
linuxshellredhat

Searching string using grep and ignoring contents in between


I am using below command to search string ."66688." in all the files inside newfolder. This is working fine.

grep --exclude=\*.{atr,out} -rnw '/tmp/newfolder' -e '."66688"'

However I the number 66688 in between ." is not constant, neither the length of the number. Hence I want to modify this command to grep file ."WHATEVER_IN_BETWEEN_DOESNT_MATTER"

grep --exclude=\*.{atr,out} -rnw '/tmp/newfolder' -e '."66688"'

Solution

  • You may use a regex here:

    grep --exclude=\*.{atr,out} -rnw '/tmp/newfolder' -e '\.".*"'
    

    \.".*" will match any text that starts with ." and ends with ".