Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi!
i have 3 text files with different patterns.
(actualy they are lists of files in different formats)what i need to do is write script that produces a report that shows if the pattern is found in all 3 files.
for example:
PATTERN : file1 : file2 : file3
-----------------------
MONSTER : YES : YES : YES
MASTER : NO : NO : YES
SLAVE : YES : YES : NO
.........i can retrieve list of patterns from each file with:
cat file1.txt | grep -v "\*\:\|\#" | awk 'BEGIN { FS = ":" } { print $1}'
cat file2.txt | grep -v "\*\:\|\#" | awk 'BEGIN { FS = ":" } { print $1}'cat file3.txt | grep -v \# | awk 'BEGIN { FS = "/" } { print $4}'
but how can i put all this together to make report?

Can you put some samples of the original 3 input files and what exactly the output is required ?
This will make it easier for us to give some sort of suggestions..
Regards,
Devaraj Takhellambam

this is a bit long but it will work.
cat file1.txt | grep -v "\*\:\|\#" | awk 'BEGIN { FS = ":" } { print $1}' > infile
cat file2.txt | grep -v "\*\:\|\#" | awk 'BEGIN { FS = ":" } { print $1}' >> infile
cat file3.txt | grep -v \# | awk 'BEGIN { FS = "/" } { print $4}' >>infile
sort -u infile > outfile
#!/bin/ksh
echo "PATTERN:File1:File2:Fil3"
while read line
do
if [ `grep -c "$line" file1` -gt 0 ]
then
echo "$line:Yes:---"
else
echo "$line:No:---"
fi
if [ `grep -c "$line" file2` -gt 0 ]
then
echo "-----:Yes:---"
else
echo "-----:No:---"
fi
if [ `grep -c "$line" file3` -gt 0 ]
then
echo "-----:---:Yes"
else
echo "-----:---:No"
fi
done < "outfile"PS: you have to work around a bit on the formatting of the output.
cheers,
Devaraj Takhellambam
Regards,
Devaraj Takhellambam

cat file1.txt | grep -v "\*\:\|\#" | awk 'BEGIN { FS = ":" } { print $1}' > infile
cat file2.txt | grep -v "\*\:\|\#" | awk 'BEGIN { FS = ":" } { print $1}' >> infile
cat file3.txt | grep -v \# | awk 'BEGIN { FS = "/" } { print $4}' >>infile
sort -u infile > outfile
echo "PATTERN:File1:File2:Fil3"
while read line
do
if [ `grep -c "$line" file1` -gt 0 ]
then
var1="Yes"
else
var1="No"
fi
if [ `grep -c "$line" file2` -gt 0 ]
then
var2="Yes"
else
var2="No"
fi
if [ `grep -c "$line" file3` -gt 0 ]
then
var3="Yes"
else
var3="No"
fi
echo "$line:$var1:$var2:$var3"
done < "outfile"
RESULT:
PATTERN:File1:File2:Fil3
MASTER:Yes:Yes:No
MONSTER:Yes:No:No
NICE:Yes:Yes:No
NSTER:Yes:No:No
SLAVE:Yes:Yes:Yes
TEMP:No:No:Yes
TEST:Yes:Yes:YesRegards,
Devaraj Takhellambam

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |