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

👤 Login to reply

RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 12:24 PM EDT
Location: Aachen, Germany
Posts: 13,082
Thanks: 452
Thanked 4,017 Times in 3,693 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
arunkumar_mca arunkumar_mca is offline
Registered User
 
Join Date: Oct 2004
Last Activity: 22 June 2018, 11:25 AM EDT
Posts: 416
Thanks: 81
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
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 12:24 PM EDT
Location: Aachen, Germany
Posts: 13,082
Thanks: 452
Thanked 4,017 Times in 3,693 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)
arunkumar_mca arunkumar_mca is offline
Registered User
 
Join Date: Oct 2004
Last Activity: 22 June 2018, 11:25 AM EDT
Posts: 416
Thanks: 81
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 08:05 AM..
Sponsored Links
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 12:24 PM EDT
Location: Aachen, Germany
Posts: 13,082
Thanks: 452
Thanked 4,017 Times in 3,693 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
arunkumar_mca arunkumar_mca is offline
Registered User
 
Join Date: Oct 2004
Last Activity: 22 June 2018, 11:25 AM EDT
Posts: 416
Thanks: 81
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
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 July 2018, 12:24 PM EDT
Location: Aachen, Germany
Posts: 13,082
Thanks: 452
Thanked 4,017 Times in 3,693 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
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:45 AM
building table from list f_o_555 Shell Programming and Scripting 2 12-15-2009 03:46 AM
Why are so many dirs used in solaris hierarchy? wrapster Solaris 1 06-19-2008 10:40 AM
Linux Filesystem Hierarchy tayyabq8 Tips and Tutorials 0 01-31-2007 02:55 AM



All times are GMT -4. The time now is 12:49 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?