Register
It is currently Wed Oct 22, 2014 6:15 am

Help to Convert CSV File Contents into Groups


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Thu Jul 22, 2010 7:16 am   

Joined: Thu Jul 22, 2010 6:57 am
Posts: 1
Hi I have the text file like this
"A"
"AA Info"
"AA Text"
"AAA"
"ABC"
"ABC Info"
"ABC Tech"
"AGH"
"SYN"
"SYMBony"
"SYN BEREN"
Like about 2000 lines

Output would be in Column with groups like following

"A"
"AA Info", "AA Text"
"AAA"
"ABC","ABC Info","ABC Tech"
"AGH"
"SYN", "SYN BEREN"
"SYMBony"
.................

Please help to me perform this output


Top
 Profile  
 PostPosted: Thu Jul 22, 2010 11:51 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
I hope this works for the rest of your data as well.
The sort at the end is necessary because of the 'randomness' of awk's 'for (i in arr)' loop.

Code:
sed "s/\"//g" | awk '{
  arr[$1]=(arr[$1]?arr[$1]", ":"")"\""$0"\"";
} END {
  for (i in arr)
    printf("%s\n", arr[i]);
}' | sort


if the sort places AAA above AA, then replace it with 'LC_ALL=C sort'


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP