Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

awk 3 files together

Original Message
Name: alusvedejs
Date: November 17, 2006 at 03:13:39 Pacific
Subject: awk 3 files together
OS: unix
CPU/Ram: x
Model/Manufacturer: x
Comment:
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?



Report Offensive Message For Removal


Response Number 1
Name: Devaraj (by Fidy)
Date: November 17, 2006 at 08:04:36 Pacific
Subject: awk 3 files together
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 2
Name: Devaraj (by Fidy)
Date: November 19, 2006 at 21:58:09 Pacific
Subject: awk 3 files together
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 3
Name: Devaraj (by Fidy)
Date: November 19, 2006 at 22:47:52 Pacific
Subject: awk 3 files together
Reply: (edit)
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:Yes

Regards,
Devaraj Takhellambam


Report Offensive Follow Up For Removal

Response Number 4
Name: alusvedejs
Date: November 19, 2006 at 23:41:34 Pacific
Subject: awk 3 files together
Reply: (edit)
i tried response #3
it works!

thanks a lot Deravaj!


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: awk 3 files together

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




My PC has been hijacked!

Lexmark 2600 Printer Issues

btk1w1 infected start here post

Unwanted message remians on screen

Slow boot time


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC