Display latest record from file based on multiple columns combination


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Display latest record from file based on multiple columns combination
# 1  
Old 03-19-2015
Display latest record from file based on multiple columns combination

I have requirement to print latest record from file based on multiple columns combination.
Code:
EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/16/2015 100004 03/16/2015 100005 001
EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/18/2015 140003 03/18/2015 140004 001
EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/18/2015 220006 03/18/2015 220014 001
EWAPE EW1SLE00_H EW1SOMU01 TIME_OVERRUN 03/12/2015 100000 03/12/2015 114500 001
EWAPE EW1SLE00_H EW1SOMU01 COMPLETED 03/16/2015 100001 03/16/2015 100003 001
EWAPE EW1SLE00_H EW1SOMU01 COMPLETED 03/18/2015 220000 03/18/2015 220005 001

Above is the sample data. Excepted output is given below. I was able to manage sorting the data but now I need to print latest record from file based on column 1,2,3,4,5 combination.
Code:
EWAPE EW1SLE0000 EW1SOMU01 ABORTED 03/18/2015 220006 03/18/2015 220014 001
EWAPE EW1SLE00_H EW1SOMU01 COMPLETED 03/18/2015 220000 03/18/2015 220005 001

Thanks,
Mallik.

Last edited by Scrutinizer; 03-19-2015 at 04:56 AM.. Reason: Formatting, code tags
# 2  
Old 03-19-2015
Presumably you mean the first 3 columns, rather than 5? Try:
Code:
awk '{A[$1,$2,$3]=$0} END{for(i in A) print A[i]}' file

or, to preserve the original order:
Code:
awk 'NR==FNR{A[$1,$2,$3]=FNR; next} FNR==A[$1,$2,$3]' file file

where the filename is specified (and the file read) two times
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

2. Shell Programming and Scripting

Merge records based on multiple columns

Hi, I have a file with 16 columns and out of these 16 columns 14 are key columns, 15 th is order column and 16th column is having information. I need to concate the 16th column based on value of 1-14th column as key in order of 15th column. Here are the example file Input File (multiple... (3 Replies)
Discussion started by: Ravi Agrawal
3 Replies

3. Shell Programming and Scripting

Sort based on Multiple Columns in UNIX

Hi, I would like to sort a list in different ways: 1> Unique based on Field 1 with highest Field 4 For Instance Input: 1678923450;11112222333344;11-1x;2_File.xml 1678923450;11112222333344;11-1x;5_File.xml 1234567890;11113333222244;11-1x;3_File.xml Output: ... (7 Replies)
Discussion started by: DevendraG
7 Replies

4. Shell Programming and Scripting

Remove Duplicates on multiple Key Columns and get the Latest Record from Date/Time Column

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)
Discussion started by: vijaykodukula
3 Replies

5. Shell Programming and Scripting

awk script to split file into multiple files based on many columns

So I have a space delimited file that I'd like to split into multiple files based on multiple column values. This is what my data looks like 1bc9A02 1 10 1000 FTDLNLVQALRQFLWSFRLPGEAQKIDRMMEAFAQRYCQCNNGVFQSTDTCYVLSFAIIMLNTSLHNPNVKDKPTVERFIAMNRGINDGGDLPEELLRNLYESIKNEPFKIPELEHHHHHH 1ku1A02 1 10... (9 Replies)
Discussion started by: viored
9 Replies

6. Shell Programming and Scripting

Multiple records based on ';' in the record

Hi All, I have a *.csv files in a die /pro/lif/dow, (pipe delimiter file), these files are having 8 columns and 6 column(CDR_LOGIC) records are populated as below, I need to incorporate the below logic in all the *.csv files. 11||:ColumnA||:ColumnB 123||:ColumnA IIF(:ColumnA = :ColumnC then... (6 Replies)
Discussion started by: shruthidwh
6 Replies

7. Shell Programming and Scripting

sort by based on multiple columns

Hi, Is there any way to sort a file in cshell by sort command, sorting it by multiple fields, like to sort it first by the second column and then by the first column. Thanks forhead (1 Reply)
Discussion started by: Takeeshe
1 Replies

8. Shell Programming and Scripting

Sorting based on Multiple columns

Hi, I have a requirement whereby I have to sort a flat file based on Multiple Columns (similar to ORDER BY Clause of Oracle). I am getting 10 columns in the flat file and I want the file to be sorted on 1st, 3rd, 4th, 7th and 9th columns in ascending order. The flat file is pipe seperated. Any... (15 Replies)
Discussion started by: dharmesht
15 Replies

9. Shell Programming and Scripting

Script to display record spanning over multiple lines

Following are the lines from /etc/sudoers.conf bob SPARC = (OP) ALL : SGI = (OP) ALL fred ALL = (DB) NOPASSWD: ALL ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\ /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM Could you please help me with shell/perl script to display the records with... (2 Replies)
Discussion started by: Ujan
2 Replies

10. Shell Programming and Scripting

awk 3 files to one based on multiple columns

Hi all, I have three files, one is a navigation file, one is a depth file and one is a file containing the measured field of gravity. The formats of the files are; navigation file: 2006 320 17 39 0 0 *nav 21.31542 -157.887 2006 320 17 39 10 0 *nav 21.31542 -157.887 2006 320 17 39 20 0... (2 Replies)
Discussion started by: andrealphus
2 Replies
Login or Register to Ask a Question