|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | ||
|