👤
Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Compare file1 for matching line in file2 and print the difference in matching lines

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 11-07-2013
Compare file1 for matching line in file2 and print the difference in matching lines

Hello,

I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from Col4:-

File1:
Code:
+-----------------------+-----------+
| Col1 | Col2 |
+-----------------------+-----------+
| Field1 | 20951 |
| Field2 | 65327 |
| Field3 | 89256 |
| Field4 | 56292 |
+----------------------+-----------+
 
Rows = 4

Code:
File 2
+-----------------------+----------+
| Col3 | Col4 |
+-----------------------+----------+
| Field3 | 89256 |
| Field5 | 58754 |
| Field4 | 56101 |
| Field6 | 4578 |
| Field2 | 65301 |
+----------------------+-----------+
 
Rows = 5

Output:
Field1
Field2


Field1 is not there in File2. Filed2 has a different count against it.

I tried using comm for this but it won't work as after sorting File2 still won't match the Fields line by line or won't consider the counts. Another restriction is I have to compare them in shell only.


Any help will be appreciated.

Thanks

Last edited by joeyg; 11-07-2013 at 08:29 AM.. Reason: Please wrap data and commands/scripts inside CodeTags
# 2  
Old 11-07-2013
Please explain the restriction

Why must be done in shell?
If this is homework, there is a specific location to post homework requests.
# 3  
Old 11-07-2013
Quote:
Originally Posted by joeyg
Why must be done in shell?
If this is homework, there is a specific location to post homework requests.
The Package which runs the checks is designed in a way that it accepts only shell scripts or sql files. We are generating these two files via a shell script so need the rest of work to be done in shell itself.
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Compare file1 and file2, print matching lines in same order as file1 pathunkathunk UNIX for Dummies Questions & Answers 4 02-10-2015 01:48 AM
Replacing first field of file2 with the second filed of file1 for matching cases ailnilanjan Shell Programming and Scripting 6 11-06-2014 05:14 AM
Based on column in file1, find match in file2 and print matching lines pathunkathunk Shell Programming and Scripting 2 03-27-2013 01:21 AM
Pattern Matching & replacing of content in file1 with file2 siramitsharma Shell Programming and Scripting 4 03-09-2013 05:59 AM
Insert lines above matching line with content from matching ysrini Shell Programming and Scripting 1 02-08-2013 04:42 PM
if matching strings in file1 and file2, add column from file1 to file2 pathunkathunk UNIX for Dummies Questions & Answers 3 07-19-2012 11:02 PM
Compare values in two files. For matching rows print corresponding values from File 1 in File2. Santoshbn Shell Programming and Scripting 10 05-21-2012 11:23 AM
print contents of file2 for matching pattern in file1 - AWK i.scientist UNIX for Advanced & Expert Users 6 09-07-2009 11:45 PM
Compare multiple fields in file1 to file2 and print line and next line gillesc_mac Shell Programming and Scripting 7 03-16-2009 06:26 AM
awk/sed search lines in file1 matching columns in file2 floripoint Shell Programming and Scripting 1 12-17-2008 10:36 PM


All times are GMT -4. The time now is 02:45 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password