|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sort field and uniq
I have a flatfile A.txt Code:
2012/12/04 14:06:07 |trees|Boards 2, 3|denver|mekong|mekong12 2012/12/04 17:07:22 |trees|Boards 2, 3|denver|mekong|mekong12 2012/12/04 17:13:27 |trees|Boards 2, 3|denver|mekong|mekong12 2012/12/04 14:07:39 |rain|Boards 1|tampa|merced|merced11 How do i sort and get latest date time with uniq duplicate field 6? Out put will be Code:
2012/12/04 17:13:27 |trees|Boards 2, 3|denver|mekong|mekong12 2012/12/04 14:07:39 |rain|Boards 1|tampa|merced|merced11 I used this code but did not work Code:
sort -t\| +5 -6 0 -1 A.txt | uniq Thanks for showing me. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
awk -f saber.awk myFile where saber.awk is: Code:
BEGIN {
FS=OFS="|"
}
{
f1=$1; gsub("[^0-9]","",f1)
if (f1 > val[$NF]) {
val[$NF]=f1
arr[$NF]=$0
}
}
END {
for (i in arr)
print arr[i]
}Last edited by vgersh99; 12-05-2012 at 03:08 PM.. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
try also (a little cheesy): Code:
sort -r -t\| -k6 A.txt | awk -F"|" '!a[$6]++' | sort -t\| -k6 or Code:
awk -F"|" '$1>a[$6]{a[$6]=$0}END {for (i in a) print a[i]}' A.txt | sort -t\| -k6Last edited by rdrtx1; 12-05-2012 at 03:20 PM.. |
|
#4
|
|||
|
|||
|
Thanks all. It also work with Code:
sort -t\| -k6,6 -u A.txt Last edited by Franklin52; 12-06-2012 at 03:58 AM.. Reason: Please use code tags for data and code samples |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with Uniq and sort | pinnacle | Shell Programming and Scripting | 4 | 05-06-2009 11:32 AM |
| How to use uniq on a certain field? | Bandit390 | Shell Programming and Scripting | 1 | 12-02-2008 04:40 PM |
| Uniq using only the first field | Digby | UNIX for Dummies Questions & Answers | 8 | 01-16-2008 05:25 AM |
| sort and uniq in perl | reggiej | Shell Programming and Scripting | 4 | 05-18-2006 10:46 PM |
| sort/uniq | jimmyflip | UNIX for Dummies Questions & Answers | 3 | 10-17-2002 05:09 AM |
|
|