bash - To find latest entry for a particular record in the unix file -
i have file has multiple entries single record. example:
abc~20160120~120 abc~20160125~150 xyz~20160201~100 abc~20160205~200 xyz~20160202~90 pqr~20160102~250
the first column record name, second column date , third column entry particular date.
now want display in file latest entry particular record. how output should like
abc~20160205~200 xyz~20160202~90 pqr~20160102~250
can shell script same? keeping in mind have many records needs sorted first according record name , taking out latest 1 each record according date.
sort lines record name , date reversed, use -u
unique flag of sort output first entry each record:
sort -t~ -k1,2r < input-file | sort -t~ -k1,1 -u
Comments
Post a Comment