I am pretty new to the terminal and command lines, from what I have found out grep seems to be the right tool to search files for specific text strings.
I have a folder with many huge text files and I would like to only keep those lines of each file that contain a certain string (e.g. "/foobar"., for instance:
file content:
lorem ipsum
trololo /foobar abc
dolor sit
/foobar def
shall afterwards be:
trololo /foobar abc
/foobar def
I guess the command looks something like this
grep -wE "(/foobar)"
but I have no clue how to tell the command to only keep those lines and do that for each file that you find in the current folder.
Would you do that with find
or does grep have an own functionality for that? Something like:
find ./* -exec do grep stuff here
-R
2. foobar def
in the result when it doesn't include the specified string/foobar
?