04-11-2008
Comparing the common columns of a table in two files
Hi,
I have two text files.The first and the 2nd file have data in the same format
For e.g. The first file has
BOOKS COUNT: 40
BOOKS AUTHOR1 SUM:1018 MAX:47 MIN:1 AVG:25.45
BOOKS AUTHOR3 SUM:181 MAX:48 MIN:3 AVG:18.1
Note:Read it as Table columnname sum(column) max(column) min(column)
File2 contains
BOOKS COUNT: 40
BOOKS AUTHOR1 SUM:1018 MAX:45 MIN:2 AVG:23.55
BOOKS AUTHOR2 SUM:561 MAX:49 MIN:1 AVG:21.5769231
BOOKS AUTHOR3 SUM:181 MAX:48 MIN:3 AVG:18.1
The file 2 contains the additional column named AUTHOR2.
Comparison should be such that the column AUTHOR1 in file 1 is compared with the column AUTHOR1 in file 2.
Here The values of column AUTHOR1 in the table BOOKS mismatches with the other file.
I should write a script to compare the columns of the table as said and report the mismatches to a different file and also report the additioanl columns present in the 2nd file.
The output should be in this format.
Column AUTHOR1 in the tabloe BOOKS mismatches.
BOOKS AUTHOR1 SUM:1018 MAX:47 MIN:1 AVG:25.45
BOOKS AUTHOR1 SUM:1018 MAX:45 MIN:2 AVG:23.55
Column AUTHOR2 is additional.
I am new to unix.Please help me in writing a script to do this job.
Thanks
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Dear all,
I have two files in UNIX File1 and File2 as below:
File1:
1,1234,.,67.897,,0
1,4134,.,87.97,,4
0,1564,.,97.8,,1
File2:
2,8798,.,67.897,,0
2,8879,.,77.97,,4
0,1564,.,97.8,,1
I want to do the following:
(1) Make sure that both the files have equal number of columns and if... (1 Reply)
Discussion started by: ggopal
1 Replies
2. Shell Programming and Scripting
Dear all,
I have two files in UNIX File1 and File2 as below:
File1:
1,1234,.,67.897,,0
1,4134,.,87.97,,4
0,1564,.,97.8,,1
File2:
2,8798,.,67.897,,0
2,8879,.,77.97,,4
0,1564,.,97.8,,1
I want to do the following:
(1) Make sure that both the files have equal number of columns and if... (4 Replies)
Discussion started by: ggopal
4 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I have two files. File1.txt has 2 columns and looks like:
458739 122345
4456 122657
34200 122600
File2.txt has many columns with column 1 the same as column2 of File1.txt, but with lot more rows:
122786 abcdefg user1@email
122778 uuhjeufh user2@email... (1 Reply)
Discussion started by: ursaan
1 Replies
4. Shell Programming and Scripting
Hello,
I have two files as 1.txt and 2.txt with number as columns.
1.txt
0 53.7988
1 -30.0859
2 20.1632
3 14.2135
4 14.6366
5 -37.6258
.
.
.
31608 -8.57333
31609 -2.58554
31610 -24.2857
2.txt (1 Reply)
Discussion started by: AKD
1 Replies
5. Shell Programming and Scripting
Hi Friends,
I have an input file like this
cat input1
x 1
y 2
z 3
a 2
b 4
c 6
d 9
cat input2
x 7
h 8
k 9
l 5
m 9
d 12 (5 Replies)
Discussion started by: jacobs.smith
5 Replies
6. Shell Programming and Scripting
Hello,
Suppose I have these 2 tab delimited files, where the second column in first file contains matching values from first column of the second file, I would like to get an output like this:
File A
1 A
2 B
3 C
File B
A Apple
C Cinnabon
B Banana
I would like... (1 Reply)
Discussion started by: Mohamed EL Hadi
1 Replies
7. UNIX for Dummies Questions & Answers
Hi, I am trying to selectively merge two files based on keys reported in the 1st column.
File1:
#file1-header1
file1-header2
111 qwe rtz uio
198 asd fgh jkl
165 yxc
789 poi uzt rew
89 lkj
File2:
#file2-header2
file2-header2
165 ghz nko2 ... (2 Replies)
Discussion started by: dovah
2 Replies
8. UNIX for Beginners Questions & Answers
I have two files:
File_1:
@M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86
GGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCAGAAGCAGCAT
+
GGGGGGGGGGGGGGGGGCCGGGGGF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8F
... (3 Replies)
Discussion started by: Xterra
3 Replies
9. Shell Programming and Scripting
Hi all,
I've multiple files. In this case 5. Space separated columns. Each file has 12 columns. Each file has 300-400K lines.
I want to get the output such that if a value in column 2 is present in all the files then get all the columns of that value and print it side by side.
Desired output... (15 Replies)
Discussion started by: genome
15 Replies
10. UNIX for Beginners Questions & Answers
I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ?
Source File
*************
# file: /local/test_1
# owner: own
#... (4 Replies)
Discussion started by: sarathy_a35
4 Replies
LEARN ABOUT DEBIAN
alzabo::sqlmaker::postgresql
Alzabo::SQLMaker::PostgreSQL(3pm) User Contributed Perl Documentation Alzabo::SQLMaker::PostgreSQL(3pm)
NAME
Alzabo::SQLMaker::PostgreSQL - Alzabo SQL making class for PostgreSQL
SYNOPSIS
use Alzabo::SQLMaker;
my $sql = Alzabo::SQLMaker->new( sql => 'PostgreSQL' );
DESCRIPTION
PostgreSQL-specific SQL creation.
METHODS
Almost all of the functionality inherited from "Alzabo::SQLMaker" as is. The only overridden methods are "limit()" and "get_limit()", as
PostgreSQL does allow for a "LIMIT" clause in its SQL.
EXPORTED SQL FUNCTIONS
SQL may be imported by name or by tags. They take arguments as documented in the PostgreSQL documentation (version 3.23.39). The func-
tions (organized by tag) are:
:math
PI
RANDOM
ABD
CEIL
DEGREES
FLOOR
FACTORIAL
SQRT
CBRT
EXP
LN
RADIANS
ACOS
ASIN
ATAN
ATAN2
COS
COT
SIN
TAN
ROUND
TRUNC
LOG
POW
MOD
TO_CHAR
:string
LENGTH
CHAR_LENGTH
CHARACTER_LENGTh
OCTET_LENGTH
TIRM
UPPER
LOWER
INITCAP
ASCII
TO_ASCII
STRPOS
POSITION
TO_NUMBER
TO_DATE
TO_TIMESTAMP
REPEAT
RPAD
LPAD
SUBSTR
:datetime
NOW
CURRENT_DATE
CURRENT_TIME
CURRENT_TIMESTAMP
TIMEOFDAY
ISFINIT
TIMESTAMP
TO_CHAR
DATE_PART
DATE_TRUNC
EXTRACT
OVERLAPS
:network
BROADCAST
HOST
NETMASK
MASKLEN
NETWORK
TEXT
ABBREV
:aggregate
These are functions which operate on an aggregate set of values all at once.
COUNT
AVG
MIN
MAX
SUM
STDDEV
VARIANCE
:system
These are functions which return information about the Postgres server.
CURRENT_USER
SYSTEM_USER
USER
:control
These are flow control functions:
NULLIF
COALESCE
:misc
These are functions which don't fit into any other categories.
ENCRYPT
ENCODE
DECODE
FORMAT
INET_NTOA
INET_ATON
BIT_OR
BIT_AND
PASSWORD
MD5
LOAD_FILE
:common
These are functions from other groups that are most commonly used.
NOW
COUNT
AVG
MIN
MAX
SUM
DISTINCT
AUTHOR
Dave Rolsky, <dave@urth.org>
perl v5.8.8 2007-12-23 Alzabo::SQLMaker::PostgreSQL(3pm)