If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to sort in ascending, descending and ascending in single file using shell script.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-30-10, 07:23
chadavinay chadavinay is offline
Registered User
 
Join Date: Jun 2010
Posts: 2
Red face How to sort in ascending, descending and ascending in single file using shell script.

My input Test Data
--------------
P1 Y A
P2 Y C
P4 N D
P3 N C
P1 X B
P1 Y B
P5 N A

Condition: 1st to 3rd char and 6th character ascending order and 4 th char descending order.

Expected Output result
-----------------------

P1 Y A
P1 Y B
P2 Y C
P1 X B
P5 N A
P3 N C
P4 N D

Please help me it's very urgent.

Thanks for advance.

Thanks & Regards,
Viany Chada
Reply With Quote
  #2 (permalink)  
Old 06-30-10, 07:56
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Is this your homework? What have you done so far?
Reply With Quote
  #3 (permalink)  
Old 06-30-10, 08:13
chadavinay chadavinay is offline
Registered User
 
Join Date: Jun 2010
Posts: 2
Red face

This is the requirement from one of our client's.

I created sample data to understand it better.... which was updated in my query.

Thanks,
Vinay
Reply With Quote
  #4 (permalink)  
Old 07-06-10, 18:45
n_i n_i is online now
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,452
Your expected output does not match the problem description. What is it that you really need?

Anyway, the sort utility will certainly help you.
Reply With Quote
  #5 (permalink)  
Old 07-07-10, 02:38
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
To get your expected output using your input
sort -k 2,2r -k 3,3 -k 1,1
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On