Cut the final line of each sorted value | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Cut the final line of each sorted value

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-22-2013
anshaa anshaa is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 2 August 2013, 1:15 AM EDT
Posts: 21
Thanks: 4
Thanked 0 Times in 0 Posts
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 08:30 AM..
Sponsored Links
    #2  
Old 01-22-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 1 October 2014, 2:12 PM EDT
Location: San Jose, CA, USA
Posts: 4,764
Thanks: 181
Thanked 1,588 Times in 1,352 Posts
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.
Sponsored Links
    #3  
Old 01-22-2013
anshaa anshaa is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 2 August 2013, 1:15 AM EDT
Posts: 21
Thanks: 4
Thanked 0 Times in 0 Posts
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 01:21 AM.. Reason: code tags
    #4  
Old 01-23-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 10 July 2014, 12:57 PM EDT
Location: Chennai
Posts: 567
Thanks: 43
Thanked 74 Times in 72 Posts
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!!
Sponsored Links
    #5  
Old 01-23-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 1 October 2014, 2:12 PM EDT
Location: San Jose, CA, USA
Posts: 4,764
Thanks: 181
Thanked 1,588 Times in 1,352 Posts
Quote:
Originally Posted by anshaa View Post
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.
Sponsored Links
    #6  
Old 01-23-2013
srinivas matta srinivas matta is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 21 February 2013, 2:05 AM EST
Location: Hyderabad
Posts: 30
Thanks: 0
Thanked 8 Times in 8 Posts
Anshaa,

what was the logic behind your output. How did you separate those output lines. then only we can help to you.
Sponsored Links
    #7  
Old 01-24-2013
anshaa anshaa is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 2 August 2013, 1:15 AM EDT
Posts: 21
Thanks: 4
Thanked 0 Times in 0 Posts
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)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -4. The time now is 02:17 PM.