I'm writing a script that at one point needs to check the contents of another script's log file to determine how to proceed. An example record from the log file is:
"mcref04152006","060417","ANTH0415","282","272","476,983.37","465,268.44","loaded"
I want my script to return this record if:
1.) the record contains "mcref", which is declared earlier in the script as $reffilepattern, and
2.) the record contains "060417", which is declared earlier in the script as $todayyymmdd.
I don't need to be picky about which fields contain the data, because the format is consistent. I'm presently doing this to read the entire line into the variable $loadedref:
todayyymmdd=$(date +%y%m%d)
reflog=reflogfile.txt
reffilepattern="mcref"
...
loadedref=$(grep "\"$todayyymmdd\"" $reflog | grep $reffilepattern)
Obviously, this works just fine, except that piping the results of one grep into another grep seems unholy. The log file is small, so while efficiency is not a concern at this point, it will be eventually as the log file grows. I tried to combine this into one grep that says, "give me the record that contains both "mcref" (without quotes) AND "060417" (with quotes), with any number of characters in between (including none)." I've tried goofy stuff like:
grep ${reffilepattern}[A-Za-z0-9]*\"${todayyymmdd}\" $reflog
...which doesn't work. Can anyone give me some pointers here? I know I'm missing something really simple -- it's late in the day! Thanks in advance.