Cut the final line of each sorted value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut the final line of each sorted value
# 1  
Old 01-22-2013
Cut the final line of each sorted value

Hi
I have file like the below mentioned example. Need some kind of unix script to achive the output.
Input:
Code:
PA|23|2013-01-23|252
PA|23|2013-01-23|264
PA|25|2013-01-22|200
PA|23|2013-01-27|156
PA|23|2013-01-27|002
PA|23|2013-01-27|014

Output:
Code:
PA|23|2013-01-23|264
PA|25|2013-01-22|200
PA|23|2013-01-27|156
PA|23|2013-01-27|014


Last edited by anshaa; 01-22-2013 at 09:30 AM..
# 2  
Old 01-22-2013
I am not seeing any sort order for the given input where the 1st line of your input would be the final line of a sorted value. Please explain your sort order you are using.
# 3  
Old 01-23-2013
i am using the below sorting order.

Code:
sort -k1b,1 -k2b,2 -k3b,3 -k4b,4


Last edited by Scrutinizer; 01-23-2013 at 02:21 AM.. Reason: code tags
# 4  
Old 01-23-2013
That would produce
Code:
PA|23|2013-01-23|252
PA|23|2013-01-23|264
PA|23|2013-01-27|002
PA|23|2013-01-27|014
PA|23|2013-01-27|156
PA|25|2013-01-22|200

I still don't see any relation to the required OP!! Smilie
# 5  
Old 01-23-2013
Quote:
Originally Posted by anshaa
i am using the below sorting order.

sort -k1b,1 -k2b,2 -k3b,3 -k4b,4
Since your sort command doesn't specify a field separator character and since there are no blanks in your input file, the command:
Code:
sort

will produce exactly the same results. And, as I said before and as PikK45 has also noted, using this sort order and deleting the last line of the sorted results doesn't even come close to the output you said you expect.

Even if I assume that there are multiple concatenated sets of sorted lines in your input file, the output you said you expect still doesn't even come close to what you would get by deleting the last line of each sorted set of lines in your input.
# 6  
Old 01-23-2013
Anshaa,

what was the logic behind your output. How did you separate those output lines. then only we can help to you.
# 7  
Old 01-24-2013
My inital input file was somethign like below :
INPUT
Code:
SATURDAY|02-JAN-13|2|ADD|165242.56
SATURDAY|02-JAN-13|2|SUB|1602446.2
SATURDAY|02-JAN-13|2|MULT|109762.97
SATURDAY|04-JAN-13|4|ADD|299754.28
SATURDAY|04-JAN-13|4|SUB|3196764.19
SATURDAY|04-JAN-13|4|MULT|224014.41
SATURDAY|07-JAN-13|7|ADD|68130.48
SATURDAY|07-JAN-13|7|SUB|634547.65
SATURDAY|07-JAN-13|7|MULT|42885.53
SATURDAY|08-JAN-13|8|ADD|236907.27
SATURDAY|08-JAN-13|8|SUB|2495910.06
SATURDAY|08-JAN-13|8|MULT|173774.33
SATURDAY|08-JAN-13|8|ADD|236925.26
SATURDAY|08-JAN-13|8|SUB|2496364.66
SATURDAY|08-JAN-13|8|MULT|173805.1
SATURDAY|07-JAN-13|7|ADD|68362.5
SATURDAY|07-JAN-13|7|SUB|635450.66
SATURDAY|07-JAN-13|7|MULT|42927.81
SATURDAY|07-JAN-13|7|ADD|68362.5
SATURDAY|07-JAN-13|7|SUB|635686.14

after using "sort" of this file i got the below file.
Code:
SATURDAY|02-JAN-13|2|ADD|165242.56
SATURDAY|02-JAN-13|2|SUB|1602446.2
SATURDAY|02-JAN-13|2|MULT|109762.97
SATURDAY|04-JAN-13|4|ADD|299754.28
SATURDAY|04-JAN-13|4|SUB|3196764.19
SATURDAY|04-JAN-13|4|MULT|224014.41
SATURDAY|07-JAN-13|7|ADD|68130.48
SATURDAY|07-JAN-13|7|ADD|68362.5
SATURDAY|07-JAN-13|7|ADD|68362.5
SATURDAY|07-JAN-13|7|SUB|634547.65
SATURDAY|07-JAN-13|7|SUB|635450.66
SATURDAY|07-JAN-13|7|SUB|635686.14
SATURDAY|07-JAN-13|7|MULT|42885.53
SATURDAY|07-JAN-13|7|MULT|42927.81
SATURDAY|08-JAN-13|8|ADD|236907.27
SATURDAY|08-JAN-13|8|ADD|236925.26
SATURDAY|08-JAN-13|8|SUB|2495910.06
SATURDAY|08-JAN-13|8|SUB|2496364.66
SATURDAY|08-JAN-13|8|MULT|173774.33
SATURDAY|08-JAN-13|8|MULT|173805.1

But after this i need something like the below format.
Code:
SATURDAY|02-JAN-13|2|ADD|165242.56
SATURDAY|02-JAN-13|2|SUB|1602446.2
SATURDAY|02-JAN-13|2|MULT|109762.97
SATURDAY|04-JAN-13|4|ADD|299754.28
SATURDAY|04-JAN-13|4|SUB|3196764.19
SATURDAY|04-JAN-13|4|MULT|224014.41
SATURDAY|07-JAN-13|7|ADD|68362.5
SATURDAY|07-JAN-13|7|SUB|635686.14
SATURDAY|07-JAN-13|7|MULT|42927.81
SATURDAY|08-JAN-13|8|ADD|236925.26
SATURDAY|08-JAN-13|8|SUB|2496364.66
SATURDAY|08-JAN-13|8|MULT|173805.1

I need the last row from each sorted value(combination of first 4 columns)
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question