need to remove duplicates based on key in first column and pattern in last column
Given a file such as this I need to remove the duplicates.
The key is the first column.
The last column determines which record to keep, that is delete all other duplicates and only keep that one. The last column with the greatest date and time should be kept as shown in bold.
Last edited by Scott; 08-31-2010 at 01:43 PM..
Reason: Please use code tags
The only thing I don't understand is how it is able to evaluate the fist line of the key as true in order to assign the value to the array.
I added some print statements to show that it does evaluate to true.
this is the output of the modified script with the print statements showing that it evaluates to true for each first occurrence of the key value (field #1)
Could you or someone explain to me how b[$1]<=a[4]a[5] evaluates to true for the first line?
Is it saying the same as b[00060011]<=20100826010517.txt ?
When it does this in the 1st record, at this point b[$1] has No Value right?
And from what I understand about if statements in awk, they cannot be 0.
Is the value null or an empty string??
Last edited by Scott; 08-31-2010 at 01:44 PM..
Reason: Code tags
Yes, for the fist record with key 'k' the value of b[k] will be 0 or the empty string depending on whether the value is used in an equation or as a string. In this case, the expression is the comparison of the empty string with some non-empty string; a non-empty string will always test greater than "". Thus, for the first instance of the key the value will be saved.
Quote:
Originally Posted by script_op2a
And from what I understand about if statements in awk, they cannot be 0.
I'm not quite sure what you mean by an if statement cannot be zero.
I'm not quite sure what you mean by an if statement cannot be zero.
What I mean is that in order to execute what follows the relational operation of the if statement the value cannot be 0.
For example:
This returns absolutely nothing because b[$1] is 0. Or is it?
Or is it an empty string? How can you tell?
But if you do it like this:
from the working script
It does NOT evaluate to 0 and continues to what follows the if.
I guess my real question is what value does b[$1] have by itself.
What value does an empty array have in awk when no values has been assigned yet?
If it's 0, I don't understand because how can you say 0>=20100826010517.txt ?
If it IS an empty string when no values have been assigned to it yet then it would be "">=20100826010517.txt . Which I Can understand.
Could you or anyone point me to some online documentation that specifically states if the value is of an empty array 0 or "an empty string" or what it is?
Or a quote from a specific book?
Last edited by Scott; 08-31-2010 at 01:45 PM..
Reason: Code tags
if no value assign to b[$1] , b[$1] will be "" (empty) initially, but when compare in awk, it will be considered as 0.
the first a[4]a[5] is 20100826010517.txt, (has .txt in it), when compare in awk, awk is smart enough to take out all non-digital characters, and consider it as 20100826010517, then if condition is translated to :
Hi all,
I have huge a tab-delimited file with the following format and I want to remove the duplicates according to their frequency based on Column2 and Column3.
Column1 Column2 Column3 Column4 Column5 Column6 Column7
1 user1 access1 word word 3 2
2 user2 access2 ... (10 Replies)
Hi Experts ,
we have a CDC file where we need to get the latest record of the Key columns
Key Columns will be CDC_FLAG and SRC_PMTN_I
and fetch the latest record from the CDC_PRCS_TS
Can we do it with a single awk command.
Please help.... (3 Replies)
Hi all
I have following kind of input file
ESR1 PA156 leflunomide PA450192 leflunomide
CHST3 PA26503 docetaxel Pa4586; thalidomide Pa34958; decetaxel docetaxel docetaxel
I want to remove duplicates and I want to separate anything before and after PAxxxx entry into columns or... (1 Reply)
Hi all,
I have an input file like this
Now
I have to remove duplicates only in first column and nothing has to be changed in second and third column. so that output would be
Please let me know scripting regarding this (20 Replies)
Hello,
I am new to shell scripting. I have a huge file with multiple columns for example:
I have 5 columns below.
HWUSI-EAS000_29:1:105 + chr5 76654650 AATTGGAA HHHHG
HWUSI-EAS000_29:1:106 + chr5 76654650 AATTGGAA B@HYL
HWUSI-EAS000_29:1:108 + ... (4 Replies)
Hi All,
I needs to fetch unique records based on a keycolumn(ie., first column1) and also I needs to get the records which are having max value on column2 in sorted manner... and duplicates have to store in another output file.
Input :
Input.txt
1234,0,x
1234,1,y
5678,10,z
9999,10,k... (7 Replies)
Hi,
How to output the duplicate record to another file. We say the record is duplicate based on a column whose position is from 2 and its length is 11 characters.
The file is a fixed width file.
ex of Record:
DTYU12333567opert tjhi kkklTRG9012
The data in bold is the key on which... (1 Reply)
I have my data something like this
(08/03/2009 22:57:42.414)(:) king aaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbb
(08/03/2009 22:57:42.416)(:) John cccccccccccc cccccvssssssssss baaaaa
(08/03/2009 22:57:42.417)(:) Michael ddddddd tststststtststts
(08/03/2009 22:57:42.425)(:) Ravi... (11 Replies)
Hi
I have to join two files based on 1st column where 4th column of a2.txt=at and take 2nd column of a1.txt and 3rd column of a2.txt and check against source files ,if matches list those source file names.
a1.txt
a1|20090809|20090810
a2|20090907|20090908
a2.txt
a1|d|file1.txt|at... (9 Replies)