awk compare column with date format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk compare column with date format
# 1  
Old 08-10-2011
awk compare column with date format

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}'

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]'

thanks

---------- Post updated at 07:41 AM ---------- Previous update was at 06:51 AM ----------

FYI

file1
Code:
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
Code:
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
Code:
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


Last edited by Franklin52; 08-10-2011 at 06:29 PM.. Reason: Correcting code tags
# 2  
Old 08-10-2011
Code:
 
awk -F~ 'NR==FNR{B[$1$10]=$1$10;A[$1]=$10;next}{ if($1 in A && A[$1]!=$10) {if(!B[$1$10])print;}}' file1 file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Format a date on additional column awk

Hi, My objective is to achieve from HB.txt 05/20/1997,1130,5.93,5.96,5.93,5.96,49200 05/20/1997,1131,5.96,5.96,5.9,5.93,252400 05/14/1997,1132,5.93,5.99,5.93,5.99,89600 05/15/1997,1133,5.93,5.93,5.71,5.74,203200 into adding a day column by using the first column - date. ... (9 Replies)
Discussion started by: benchin_
9 Replies

2. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

3. Shell Programming and Scripting

How to awk or grep the last column in file when date on column contains spaces?

Hi have a large spreadsheet which has 4 columns APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96085 Corp IT Desktop and Apps APM00111803814 server_2 96034 Storage Mgmt Team APM00111803814 server_2 96152 GWP... (6 Replies)
Discussion started by: kieranfoley
6 Replies

4. Shell Programming and Scripting

How to change the format of the date column in a flat file?

Hi, i have a flat file namely temp.txt with this data below ID|name|contact_date 101|Kay|2013-12-26 102|let|2013-12-26 I need to modify the date data in the flat file into MM/DD/YYYY HH24:MI:SS format let me know the code for this. Thank you! (5 Replies)
Discussion started by: srikanth_sagi
5 Replies

5. Shell Programming and Scripting

Compare the second column of a file with the second column of another in awk

Hi, I know that this topic has been discussed in the past and I've tried to follow all the guidelines. Anyhow, I following describe my problem. I have a file (file1 , no. records = 67) containing pairs of IP addresses as follows (with single space as delimiter between the fields): example... (5 Replies)
Discussion started by: amarn
5 Replies

6. Shell Programming and Scripting

Convert date column as yyyy/mm/dd format

Hi All, I have file like “April 10, 2013”,”raj” “April 29, 2013”,”raj1” Output : “2013/04/10”,”raj” “2013/04/29”,”raj1” Please help me how to do... (9 Replies)
Discussion started by: bmk
9 Replies

7. Shell Programming and Scripting

Compare Date with String in date format

Hi, I am new to this forum, searched, but for some reason did not find much help, so a new thread. I am trying to compare date with a string which is in date format , but for some reason, system does not give me the right result. Date is coming in a file and i am comparing the same with... (2 Replies)
Discussion started by: mkstool
2 Replies

8. Shell Programming and Scripting

Convert the date format from mdy to ymd in column of file

The date format in the delimited file for one column '6/27/2011 12:00:00 AM' Is it possible o change it to '2011-06-27 12:00:00 AM' for all the records.. Thanks in advance..... (8 Replies)
Discussion started by: infernalhell
8 Replies

9. Shell Programming and Scripting

change date format and then compare dates

I have filenames filenameA_fg_MMDDYY.tar.gz filenameASPQ_fg_MMDDYY.tar.gz filenameAFTOPHYYINGH_fg_MMDDYY.tar.gz filenameAGHYSW_fg_MMDDYY.tar.gz My requiremnt needs to extract date which is in MMDDYYand change it into YYYYMMDD format. I have done the following: filedate=`echo... (5 Replies)
Discussion started by: RubinPat
5 Replies

10. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies
Login or Register to Ask a Question