Hi Everyone,
I have below record set. File is fixed widht file
101newjersyus 20150110
101nboston us 20150103
102boston us 20140106
102boston us 20140103
I need to group record based on first 3 letters in our case(101 and 102)
and sort last 8 digit in ascending order and print only last record
So output should be
You said that the input file is fixed width, but as can clearly be seen above (now that CODE tags have been added), some lines are longer than others. If the lines were fixed length (or more importantly, if the date at the ends of these lines started in the same character position in all lines), Chubler_XL's awk | sort pipeline could be changed to a sort | awk pipeline with a slightly more complex sort command and a much simpler awk command. But, since your secondary sort key is not in a fixed field, and is not in a fixed position; that won't work.
Were it a fixed width file, things would be much simpler. The following does work on your sample but will fail if positions of spaces and fields shift:
This will work on many systems. Unfortunately the standards are silent as to which line with identical keys will be printed by sort -u so there is no guarantee that it will always print the 1st line in each set of lines with identical strings in the 1st three characters of the line.
The following should work portably (as long as the 8 digit date string starts in column 13 or 14 and is preceded by a space if it starts in column 14):