Sponsored Content
Top Forums Shell Programming and Scripting Compare two files using awk command recursively Post 302899274 by Ragu14 on Monday 28th of April 2014 09:19:38 AM
Old 04-28-2014
Compare two files using awk command recursively

I want to compare two files, 1) Compare Each query result. 2) Compare Only first row of the Query output 3) Compare Time (3rd column), First file time is lesser than 2nd file then print the PO_NUM else do nothing.

File1:
Code:
C:\script>call transaction 1OPOP

C:\script>Select ID, PO_ID, TIME, DES From Table
ID          PO_NUM          TIME                        DES         
-------     ------------    ---------------             -----
11232323    1OPOP           2012-08-01-23.02.50.040000  SAMPLE  
11232324    1OPOP           2013-09-01-23.02.50.040000  SAMPLE  
11232325    1OPOP           2014-09-01-23.02.50.040000  SAMPLE  
11232326    1OPOP           2015-09-01-23.02.50.040000  SAMPLE
4 record(s) selected.

C:\script>call transaction 1XDXD

C:\script>Select ID, PO_ID, TIME, DES From Table
ID          PO_NUM          TIME                        DES         
-------     ------------    ---------------             -----
11232323    1XDXD           2012-07-01-23.02.50.040000  SAMPLE  
11232324    1XDXD           2013-09-01-23.02.50.040000  SAMPLE  
11232325    1XDXD           2014-08-01-23.02.50.040000  SAMPLE  
3 record(s) selected.

C:\script>call transaction 1IOIO

C:\script>Select ID, PO_ID, TIME, DES From Table
ID          PO_NUM          TIME                        DES         
-------     ------------    ---------------             -----
11232323    1IOIO           2011-06-01-23.02.50.040000  SAMPLE  
11232324    1IOIO           2012-09-01-23.02.50.040000  SAMPLE  
2 record(s) selected.

File2:

Code:
C:\script>call transaction 1OPOP

C:\script>Select ID, PO_ID, TIME, DES From Table
ID          PO_NUM          TIME                    DES         
-------     ------------    ---------------             -----
11232323    1OPOP           2012-09-01-23.02.50.040000  SAMPLE  
11232324    1OPOP           2013-09-01-23.02.50.040000  SAMPLE  
11232325    1OPOP           2014-09-01-23.02.50.040000  SAMPLE  
11232326    1OPOP           2015-09-01-23.02.50.040000  SAMPLE
4 record(s) selected.

C:\script>call transaction 1XDXD

C:\script>Select ID, PO_ID, TIME, DES From Table
ID          PO_NUM          TIME                    DES         
-------     ------------    ---------------             -----
11232323    1XDXD           2012-08-01-23.02.50.040000  SAMPLE  
11232324    1XDXD           2013-09-01-23.02.50.040000  SAMPLE  
11232325    1XDXD           2014-08-01-23.02.50.040000  SAMPLE  
3 record(s) selected.

C:\script>call transaction 1IOIO

C:\script>Select ID, PO_ID, TIME, DES From Table
ID          PO_NUM          TIME                DES         
-------     ------------    ---------------             -----
11232323    1IOIO           2011-05-01-23.02.50.040000  SAMPLE  
11232324    1IOIO           2012-09-01-23.02.50.040000  SAMPLE  
2 record(s) selected.

Thanks in Advance
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk compare 2 files

Hi i hope some awk gurus here can help me.. here is what i need i have 2 files: File1 152445 516532 405088.pdf 152445 516533 405089.pdf 152491 516668 405153.jpg 152491 520977 408779.jpg 152491 0 409265.pdf File2 516532 /tmp/MainStreet_Sum09_Front_FNL.pdf 516533... (9 Replies)
Discussion started by: kenray
9 Replies

2. Shell Programming and Scripting

using awk to compare two files

Hi, I have two tab separated files; file1: S.No ddi fi cu o/l t+ t- 1 0.5 0.6 o 0.1 0.2 2 0.2 0.3 l 0.3 0.4 3 0.5 0.8 l 0.1 0.6 file2: S.No ddi fi cu o/l t+ t- 1 0.8 0.9 o 0.5 0.6 2 0.5 0.2 o 0 0 3 0.2 0.3 l 0 0 4 0.5 0.6 l 0 0 (1 Reply)
Discussion started by: vasanth.vadalur
1 Replies

3. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

4. Shell Programming and Scripting

Compare two files with awk

Hello, I have a script which extracts the values from a csv file when a specific date is entered : #!/bin/sh awk 'BEGIN{printf("Entrez la date : "); getline date < "-"} $0 ~ date {f=1;print;next} /^{2}\//{f=0} f' file1.csv This script gives me a number of lines with different values. ... (6 Replies)
Discussion started by: freyr
6 Replies

5. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

6. Shell Programming and Scripting

Script to compare files recursively using sdiff

Hi All, I have been surfing to get some idea on how to compare same files from two different paths. one path will have oldfiles directory and another path will have newfiles directory. Each main directories will have sub-directories in them and each sub-directories inturn will have... (3 Replies)
Discussion started by: Optimus81
3 Replies

7. Shell Programming and Scripting

awk compare files

I have a below requirement and trying to compare the files using awk File 1 - Already stored on a prev day id | text | email id --------------------------------- 89564|this is line 1 | xyz@sample.txt 985384|this is line 2 | abc@sample.txt 657342|this is line 3 |... (3 Replies)
Discussion started by: rakesh_411
3 Replies

8. UNIX for Dummies Questions & Answers

awk command to compare files by column

So I have this issue. I have 4 files. the first one is the master file who has all possible combinations: file 1 - a - b - c - d - e the other three have some of the letters and a number instead of - for example file 2 34 a 5 c file 3 10 b 12 ... (3 Replies)
Discussion started by: Quijotes
3 Replies

9. Shell Programming and Scripting

[awk] Compare two files

HI!! I am trying to compare two files using AWK but I have some problems. I need to count how many times letters are used in two texts. This is my script { long=length($0) for (i=1;i<=long;i++) { aux=substr($0,i,1) if ( aux != " " && aux != "" ) ... (7 Replies)
Discussion started by: ettore8888
7 Replies

10. Shell Programming and Scripting

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies
Data::Compare::Plugins(3)				User Contributed Perl Documentation				 Data::Compare::Plugins(3)

NAME
Data::Compare::Plugins - how to extend Data::Compare DESCRIPTION
Data::Compare natively handles several built-in data types - scalars, references to scalars, references to arrays, references to hashes, references to subroutines, compiled regular expressions, and globs. For objects, it tries to Do The Right Thing and compares the underlying data type. However, this is not always what you want. This is especially true if you have complex objects which overload stringification and/or numification. Hence we allow for plugins. FINDING PLUGINS
Data::Compare will try to load any module installed on your system under the various @INC/Data/Compare/Plugins/ directories. If there is a problem loading any of them, an appropriate warning will be issued. Because of how we find plugins, no plugins are available when running in "taint" mode. WRITING PLUGINS
Internally, plugins are "require"d into Data::Compare. This means that they need to evaluate to true. We make use of that true value. Where normally you just put: 1; at the end of an included file, you should instead ensure that you return a reference to an array. This is treated as being true so satisfies perl, and is a damned sight more useful. Inside that array should be either a description of what this plugin is to do, or references to several arrays containing such descriptions. A description consists of two or three items. First a string telling us what the first data-type handled by your plugin is. Second, (and optional, defaulting to the same as the first) the second data-type to compare. To handle comparisons to ordinary scalars, give the empty string for the data-type, ie: ['MyType', '', sub { ...}] Third and last, we need a reference to the subroutine which does the comparison. That subroutine should expect to take two parameters, which will be of the specified type. It should return 1 if they compare the same, or 0 if they compare different. Be aware that while you might give a description like: ['Type1', 'Type2', sub { ... }] this will handle both comparing Type1 to Type2, and comparing Type2 to Type1. ie, comparison is commutative. If you want to use Data::Compare's own comparison function from within your handler (to, for example, compare a data structure that you have stored somewhere in your object) then you will need to call it as Data::Compare::Compare. However, you must be careful to avoid infinite recursion by calling D::C::Compare which in turn calls back to your handler. The name of your plugins does not matter, only that it lives in one of those directories. Of course, giving it a sensible name means that the usual installation mechanisms will put it in the right place, and meaningful names will make it easier to debug your code. For an example, look at the plugin that handles Scalar::Properties objects, which is distributed with Data::Compare. DISTRIBUTION
Provided that the above rules are followed I see no reason for you to not upload your plugin to the CPAN yourself. You will need to make Data::Compare a pre-requisite, so that the CPAN.pm installer does the right thing. Alternatively, if you would prefer me to roll your plugin in with the Data::Compare distribution, I'd be happy to do so provided that the code is clear and well-commented, and that you include tests and documentation. SEE ALSO
Data::Compare Data::Compare::Plugins::Scalar::Properties AUTHOR
Copyright (c) 2004 David Cantrell <david@cantrell.org.uk>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2011-07-23 Data::Compare::Plugins(3)
All times are GMT -4. The time now is 07:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy