Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-07-2013   -   Original Discussion by RasB15
RasB15's Unix or Linux Image
RasB15 RasB15 is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 7 November 2013, 9:04 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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 09:29 AM.. Reason: Please wrap data and commands/scripts inside CodeTags
Sponsored Links
    #2  
Old Unix and Linux 11-07-2013   -   Original Discussion by RasB15
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 22 February 2018, 7:58 AM EST
Location: Within two miles of a Dunkin donuts.
Posts: 2,478
Thanks: 140
Thanked 206 Times in 181 Posts
Please explain the restriction

Why must be done in shell?
If this is homework, there is a specific location to post homework requests.
Sponsored Links
    #3  
Old Unix and Linux 11-07-2013   -   Original Discussion by RasB15
RasB15's Unix or Linux Image
RasB15 RasB15 is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 7 November 2013, 9:04 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by joeyg View Post
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.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Based on column in file1, find match in file2 and print matching lines pathunkathunk Shell Programming and Scripting 2 03-27-2013 02:21 AM
if matching strings in file1 and file2, add column from file1 to file2 pathunkathunk UNIX for Dummies Questions & Answers 3 07-20-2012 12:02 AM
print contents of file2 for matching pattern in file1 - AWK i.scientist UNIX for Advanced & Expert Users 6 09-08-2009 12:45 AM
Compare multiple fields in file1 to file2 and print line and next line gillesc_mac Shell Programming and Scripting 7 03-16-2009 07:26 AM
awk/sed search lines in file1 matching columns in file2 floripoint Shell Programming and Scripting 1 12-17-2008 11:36 PM



All times are GMT -4. The time now is 06:42 PM.