Computing.Net > Forums > Unix > awk 3 files together

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk 3 files together

Reply to Message Icon

Name: alusvedejs
Date: November 17, 2006 at 03:13:39 Pacific
OS: unix
CPU/Ram: x
Product: 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?




Sponsored Link
Ads by Google

Response Number 1
Name: Devaraj (by Fidy)
Date: November 17, 2006 at 08:04:36 Pacific
Reply:

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


0

Response Number 2
Name: Devaraj (by Fidy)
Date: November 19, 2006 at 21:58:09 Pacific
Reply:

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


0

Response Number 3
Name: Devaraj (by Fidy)
Date: November 19, 2006 at 22:47:52 Pacific
Reply:

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


0

Response Number 4
Name: alusvedejs
Date: November 19, 2006 at 23:41:34 Pacific
Reply:

i tried response #3
it works!

thanks a lot Deravaj!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: awk 3 files together

awk two files together www.computing.net/answers/unix/awk-two-files-together/8324.html

awking a file www.computing.net/answers/unix/awking-a-file/7200.html

awk-merging files by field number www.computing.net/answers/unix/awkmerging-files-by-field-number/538.html