I'm basicly trying to write a script that will search through all files in the /home directory and sorting out key words such as kill, bomb, porn ... etc. Then having the output displayed as
User "username" has "the keyword" in "filename"
I'm pretty new to this and I'm pretty stuck
This is what I have so far
for X in kill bomb porn do USERN=`grep –i –r “$X /home | cut –d “/ –f 3` WORD=`grep –i –o –r “$X /home | cut –d “: –f 2` FILE=`grep –i –r “$X /home | cut –d “: –f 1` Echo “User $USERN has $WORD in $FILE done
this works fine if the key word comes up in only one file, but if it comes up in multiple files the output comes out like
jenkins has kill
kill in /home/blah/mydocuments/mytext
(blah and jenkins are my two users)
thats what happens when kill shows up in two files
any suggestions of how to fix that?