Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Building hierarchy with the list

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 10-05-2017   -   Original Discussion by arunkumar_mca
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 January 2018, 10:01 AM EST
Location: Aachen, Germany
Posts: 11,982
Thanks: 356
Thanked 3,692 Times in 3,390 Posts
With a ">" separator, there's no 4th field to serve as a sort key in above data. I'm sorry, I don't get what you're after.
Sponsored Links
    #9  
Old Unix and Linux 10-05-2017   -   Original Discussion by arunkumar_mca
arunkumar_mca's Unix or Linux Image
arunkumar_mca arunkumar_mca is offline
Registered User
 
Join Date: Oct 2004
Last Activity: 11 December 2017, 10:01 AM EST
Posts: 395
Thanks: 61
Thanked 2 Times in 2 Posts
sorry If I am not clear. Basically my input is like below with ID's. I want to sort 4th columns with the hierarchy sort as MANUAL,POO TO etc . I have added expected output below

Original


Code:
179341~1704489~1704480~704925680_TOTAL->MANUAL->TT IOR GSB
179341~1704497~1704480~775116444_TOTAL->POO TO->TT
179341~1704505~1704480~-572275295_TOTAL->MANUAL->MTO
179341~1704507~1704480~-611408278_TOTAL->PRIE LEL
179341~1704509~1704480~456690129_TOTAL->BTT TOO
179341~1704481~1704480~475919266_TOTAL->MANUAL->COM


Expected Output



Code:
179341~1704489~1704480~704925680_TOTAL->MANUAL->TT IOR GSB
179341~1704505~1704480~-572275295_TOTAL->MANUAL->MTO
179341~1704481~1704480~475919266_TOTAL->MANUAL->COM
179341~1704497~1704480~775116444_TOTAL->POO TO->TT
179341~1704507~1704480~-611408278_TOTAL->PRIE LEL
179341~1704509~1704480~456690129_TOTAL->BTT TOO

Sponsored Links
    #10  
Old Unix and Linux 10-05-2017   -   Original Discussion by arunkumar_mca
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 January 2018, 10:01 AM EST
Location: Aachen, Germany
Posts: 11,982
Thanks: 356
Thanked 3,692 Times in 3,390 Posts
Applying copious amounts of phantasy, (or wildly guessing, whatever you prefer) let me try to paraphrase your request, which, btw, dramatically changed during the course of the thread:

A file of records consisting of fields separated by "~" needs to be rearranged by a sub field of the 4th field which in turn is separated by "->". I use the term "rearranged" as I can't dream up an algorithm to sort character B after P after M. The algorithm with which to rearrange is not defined.
The Following User Says Thank You to RudiC For This Useful Post:
arunkumar_mca (10-05-2017)
    #11  
Old Unix and Linux 10-05-2017   -   Original Discussion by arunkumar_mca
arunkumar_mca's Unix or Linux Image
arunkumar_mca arunkumar_mca is offline
Registered User
 
Join Date: Oct 2004
Last Activity: 11 December 2017, 10:01 AM EST
Posts: 395
Thanks: 61
Thanked 2 Times in 2 Posts
From a row delimited by ~ take the 4th field and from that delimited by > take the last record and group record based on the entire row . I don't need to sort I need to group basically it is ending in sort. As you mentioned I am not worried about where B comes. I need to group MANUAL and others If any it can be of any order.

The desired output can be in a form below.


Code:
179341~1704489~1704480~704925680_TOTAL->MANUAL->TT IOR GSB
179341~1704505~1704480~-572275295_TOTAL->MANUAL->MTO
179341~1704481~1704480~475919266_TOTAL->MANUAL->COM
179341~1704497~1704480~775116444_TOTAL->POO TO->TT
179341~1704507~1704480~-611408278_TOTAL->PRIE LEL
179341~1704509~1704480~456690129_TOTAL->BTT TOO

OR


Code:
179341~1704497~1704480~775116444_TOTAL->POO TO->TT
179341~1704507~1704480~-611408278_TOTAL->PRIE LEL
179341~1704509~1704480~456690129_TOTAL->BTT TOO
179341~1704489~1704480~704925680_TOTAL->MANUAL->TT IOR GSB
179341~1704505~1704480~-572275295_TOTAL->MANUAL->MTO
179341~1704481~1704480~475919266_TOTAL->MANUAL->COM

OR



Code:
179341~1704509~1704480~456690129_TOTAL->BTT TOO
179341~1704489~1704480~704925680_TOTAL->MANUAL->TT IOR GSB
179341~1704505~1704480~-572275295_TOTAL->MANUAL->MTO
179341~1704481~1704480~475919266_TOTAL->MANUAL->COM
179341~1704497~1704480~775116444_TOTAL->POO TO->TT
179341~1704507~1704480~-611408278_TOTAL->PRIE LEL


Last edited by arunkumar_mca; 10-05-2017 at 09:05 AM..
Sponsored Links
    #12  
Old Unix and Linux 10-05-2017   -   Original Discussion by arunkumar_mca
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 January 2018, 10:01 AM EST
Location: Aachen, Germany
Posts: 11,982
Thanks: 356
Thanked 3,692 Times in 3,390 Posts
"the last record" - even if I translate "record" to "field", "MANUAL" would NOT be the last.

"group record based on the entire row" - what does this mean? Is that bespoke subfield the key, or the entire row?
Sponsored Links
    #13  
Old Unix and Linux 10-05-2017   -   Original Discussion by arunkumar_mca
arunkumar_mca's Unix or Linux Image
arunkumar_mca arunkumar_mca is offline
Registered User
 
Join Date: Oct 2004
Last Activity: 11 December 2017, 10:01 AM EST
Posts: 395
Thanks: 61
Thanked 2 Times in 2 Posts
oops it is not last record it is second last . My bad.

When I mean entire row is the the record group needs to with ID as shown in example. I need to ID to be preserved with the grouping. I the example below the ID associated with the records needs be stick to it where the record moved based on grouping


Code:
179341~1704489~1704480~704925680_TOTAL->MANUAL->TT IOR GSB

Sponsored Links
    #14  
Old Unix and Linux 10-05-2017   -   Original Discussion by arunkumar_mca
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 January 2018, 10:01 AM EST
Location: Aachen, Germany
Posts: 11,982
Thanks: 356
Thanked 3,692 Times in 3,390 Posts
Try


Code:
sed 's/[~>]/&#/g' file | sort -t"#" -k5,5 | sed 's/#//g'
179341~1704509~1704480~456690129_TOTAL->BTT TOO
179341~1704481~1704480~475919266_TOTAL->MANUAL->COM
179341~1704489~1704480~704925680_TOTAL->MANUAL->TT IOR GSB
179341~1704505~1704480~-572275295_TOTAL->MANUAL->MTO
179341~1704497~1704480~775116444_TOTAL->POO TO->TT
179341~1704507~1704480~-611408278_TOTAL->PRIE LEL

The Following User Says Thank You to RudiC For This Useful Post:
arunkumar_mca (10-05-2017)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rsync building file list/catalog path/location glev2005 UNIX for Advanced & Expert Users 1 01-11-2010 11:45 AM
building table from list f_o_555 Shell Programming and Scripting 2 12-15-2009 04:46 AM
Why are so many dirs used in solaris hierarchy? wrapster Solaris 1 06-19-2008 11:40 AM
Linux Filesystem Hierarchy tayyabq8 Tips and Tutorials 0 01-31-2007 03:55 AM



All times are GMT -4. The time now is 12:04 PM.