1753544 Members
6129 Online
108795 Solutions
New Discussion юеВ

Script question !

 
SOLVED
Go to solution
chapaya_1
Frequent Advisor

Script question !

Hi ,

I have a file (name.txt) with list of names
(one name in line) ,
i want to check if any name exist in other file
(name.log ).

I know it's a play with grep,awk,cut ..

any ideas ?

BYE.
8 REPLIES 8
Sanjay Kumar Suri
Honored Contributor
Solution

Re: Script question !

Check this:

for i in `cat name.txt`
do
grep $i name.log
done


sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Jose Mosquera
Honored Contributor

Re: Script question !

Hi,

Try this:

FILES_LOG=name.log
FILES_TXT=`cat name.txt`
for FILE_TO_CHK in $FILES_TXT
do
FOUND=`grep $FILE_TO_CHK $FILES_TXT|wc -w`
if ["$FOUND" ! = "0" ]
then
echo "File $FILE_TO_CHK found into $FILES_LOG"
fi
done

If you need an exact name search try with "grep -x" option.

Rgds.
harry d brown jr
Honored Contributor

Re: Script question !

grep -f name.txt name.log

live free or die
harry
Live Free or Die
Mark Grant
Honored Contributor

Re: Script question !

harry!

Now THAT is a new one on me, thanks a lot.



No points for this post please.
Never preceed any demonstration with anything more predictive than "watch this"
harry d brown jr
Honored Contributor

Re: Script question !

Mark,

And if you install GNU's grep, you'll find that it can do even more incredible things.

"grep" & "find" are a systems administrator's best friends.

and with the pattern file (named.txt) you can do cool things like "^someword" or "someword$" or "[Tt]hat [Cc]at in a [Hh]at"....

live free or die
harry
Live Free or Die
Kyri Pilavakis
Frequent Advisor

Re: Script question !

What about the 'old' way using cmp[-l -s] fileA fileB.
The -l option will report the position(in decimal) in the file where the difference occurred.
Bosses don't undestand..HP does
H.Merijn Brand (procura
Honored Contributor

Re: Script question !

harry, if you have GNU grep (which you should anyway),

# grep -f name.txt -w name.log

will grep on WORD base, which means that if file.txt contains 'oo.c', harry's grep will also match 'foo.c', but the -w version will not, it will only match the 'oo.c'
this is exceptionally better if you consider file names as 'name.c.org' and 'blah.foo.sav' in the log

Enjoy, Have FUN! H.Merijn [ who would use perl himself ]
Enjoy, Have FUN! H.Merijn
chapaya_1
Frequent Advisor

Re: Script question !

Hi All ,

Sanjay your answer was simple and suitable for my needs .

BYE.