Recursive search for strings in files with a certain date: find -name or grep -R?

Ok, I am trying to find two sets of strings in files created today, within directories that contain a specific string in their name. I have tried different variations of grep and find without the exact results I need. I'll elaborate:

We have numerous devices made by the same vendor, but there are three different models. These devices are in 38 states, with multiple devices in each state. We have used this information to create hostnames for these devices. Here's and example of the format:

rbflftmy81

vendor code = rb
state = fl
city = ftmy
model = SE-800 (hence the "8")
device number = #1 (hence the "1"; subsequent devices in the same city and state would have a 2, or 3, etc.)

These devices get backed up every day, each respective device backing up into its own folder, at it's own time, but the same time each day. The node name and the year, date, and time it backed up are all part of the file name that it backs up to. The directory structure looks like this:

I basically need to execute a "grep -A 1" for the strings "port ethernet" and "port atm" on any file created on today's date in any directory with "rb" and "8" in the directory or file name, so I can get all of the strings similar to these:

But it doesn't work either. Does anyone know how to do this? Moreover, how would I get it to pull files only from today? Sorry if it's wordy and complicated. Thanks in advance!

snooly

09-28-2011 10:05 PM

grep -r is recursive, so you could just point to the parent directory which contains all the files you want to search. It might take a little bit longer, but maybe that doesn't matter.

wolverene13

09-28-2011 10:35 PM

Quote:

Originally Posted by snooly
(Post 4484975)

grep -r is recursive, so you could just point to the parent directory which contains all the files you want to search. It might take a little bit longer, but maybe that doesn't matter.

Well, the recursive grep part is working when I just use grep -R -A 1, but that pulls up files for devices with other model numbers too (i.e. rbtxklln01 and rbflwnpk11) and files from the preceding 30 days for the same device. I need to narrow it down to only files in the directory /home/configs/dsl that have the vendor code "rb" and model number "8" in their actual file name, from 9/28/2011. I was thinking that I needed to somehow search for rb......8.20110928*\.config in the name of the file itself, but I have no idea how I would do that while also searching the text within the file for the strings I need also. Any ideas?

snooly

09-28-2011 10:37 PM

You might be able to pipe the results of the first grep into another grep, thus narrowing down the stuff you want.

grep -r stuff-you-want parent-dir | grep -v stuff-you-dont-want

allend

09-29-2011 01:03 AM

You need to enclose the argument to -name in quotes to avoid shell expansion.