BIPEDU

my ideas in action

grep for a text on all files from a folder

If you want to collect the lines that contain a certain text from all files from a folder you can use this command.

find . -type f -name “irun.log” -exec grep -H “mytext” {} \; > list_results_mydata.txt

So basically it searches for files named “irun.log” and for each that is found it will search if contain the string “mytext“.

At the end it will put the results in to another file “list_results_mydata.txt

I use here -H option for grep since I want to have the name of the file and the full row with data.

Result is something like this:

./test/files/a/irun.log: aaa mytext = 45

 ./test/files/b/irun.log: fre mytext = 235

 ./test/files/c/irun.log: dt mytext = 56

….

I need this because the files are having the same name and are on different folders.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: