tags:

views:

189

answers:

1

Each logfile is titled based on the date it was created in the format YYYY-MM-DD.txt. I need to search each file for five different keywords and output five files prepended with the specific keyword and then the original logfile name. Example: Test-YYYY-MM-DD.txt

grep -i -w 'keyword1' YYYY-MM-DD.txt > Keyword1-YYYY-MM-DD.txt

If it's also possible to email each new file to a different person, that would be helpful as well.

A: 
for file in *txt
do
  if [ -f "$file" ];then
    awk '/keyword1/{print $0 > "keyword1-"FILENAME}
    /keyword2/{print $0 > "keyword2-"FILENAME}
    /keyword3/{print $0 > "keyword3-"FILENAME} ' "$file"
  fi
done

note the above does not check for ALL 5 keywords to be present.

ghostdog74