Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk compare column with date format 1

Status
Not open for further replies.

beardown

IS-IT--Management
Aug 10, 2011
3
0
0
US
I have this code to compare columns 1 and 10 between file1 and file 2 and give me all records that match column 1 but dont match column 10

However column 10 is date format mm/dd/yy and awk cant read it and compare ...i tried

CODE

awk < file1 -F~ '{print $10}'

CODE

and it gave blank screen

Is there a way to modify code to read dates and do the compare so the awk works properly

CODE

awk -F~ 'NR==FNR{A[NR]=$1$10;next}$1$10!=A[FNR]'

CODE

 
file1

25480820~a~b~c~d~e~f~g~h~09/10/09
26701789~a~b~c~d~e~f~g~h~12/06/10
26701789~a~b~c~d~e~f~g~h~03/28/13
22907330~a~b~c~d~e~f~g~h~07/29/11

file2

25480820~a~b~c~d~e~f~g~h~09/10/09
25480820~a~b~c~d~e~f~g~h~11/12/10
26701789~a~b~c~d~e~f~g~h~12/06/10
26701789~a~b~c~d~e~f~g~h~01/11/11
26701789~a~b~c~d~e~f~g~h~03/28/13
22907330~a~b~c~d~e~f~g~h~07/29/11
22907330~a~b~c~d~e~f~g~h~10/22/09
22907330~a~b~c~d~e~f~g~h~04/22/14


desired output

25480820~a~b~c~d~e~f~g~h~11/12/10
26701789~a~b~c~d~e~f~g~h~01/11/11
22907330~a~b~c~d~e~f~g~h~10/22/09
22907330~a~b~c~d~e~f~g~h~04/22/14
 
Hi

Maybe not the optimal way :
Code:
awk -F~ 'NR==FNR{f[NR]=$1;l[NR]=$10;next}{ok=0;for(i=1;i in f;i++)if(f[i]==$1)if(l[i]!=$10)ok=1;else next}ok' file1 file2
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top