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 
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

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
User blah
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?

12 Years
Discussion Span
Last Post by zerolimit

I was messing around with it some more and came up with this

for X in kill bomb porn
USERN=`grep -i -r "$X" /home | cut -d "/" -f 3`
FILE=`grep -i -r "$X" /home | cut -d ":" -f 1`
echo "User "$USERN" has the word "$X" in "$FILE"."

Problem is this way puts both users on the same line and each file on the same line also.
output is like this
User blah jenkins has the word kill in /home/blah/mydocuments/mytext /home/jenkins/mydocuments/test

I guess what i'm looking for is a way to seperate them.
so it looks like
User blah has the word kill in /home/blah/mydocuments/mytext
User jenkins has the word kill in /home/jenkins/mydocuments/test

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.