0

I can search for a word in the file by using grep for example:

grep 'total energy' file*

but I can't search for a word with =, for example:

grep 'total energy =' file*

Why? is there any solution to above issue?

campovski
  • 2,979
  • 19
  • 38
  • Possible duplicate of [Grep for special characters in Unix](https://stackoverflow.com/questions/12387685/grep-for-special-characters-in-unix) – GhostCat Sep 04 '17 at 14:38

1 Answers1

0

You have to use double quotes ("") like this

grep "total energy =" /your/file

where you substitute /your/file with the name of your file. Read difference between "" and ''.


To search through all files in current directory, you want the next command

find ./ -type f -exec grep "total energy =" {} \;

What this does is it first finds all files in current dir using find (./ denotes current directory, -type f stands for only files). Then it executes grep search for "total energy =". \ denotes where the end of -exec is, in case there would be anything else behind it.

If you only want to search through files that are like frame[number].inp, you can use regex with find:

find ./ -regextype posix-extended -regex '.*?\.inp' -exec grep "total energy =" {} \;
campovski
  • 2,979
  • 19
  • 38