The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to listout the files based on group by the date...? psiva_arul UNIX for Dummies Questions & Answers 3 04-21-2008 09:03 AM
Newly created files default group and write permissions goldfish UNIX for Dummies Questions & Answers 2 02-20-2008 06:39 PM
Recursive search for group or other writeable 'dot' files maficdan Security 5 02-14-2008 09:43 PM
Monkcast #12: IBM HW group OEMs Solaris to chagrin of SW group & a ... - ZDNet.com bl iBot UNIX and Linux RSS News 0 08-17-2007 04:30 PM
listing sequential files as one group... kentm UNIX for Advanced & Expert Users 1 01-24-2007 06:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-21-2005
hellsd hellsd is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 20
group by in files :-)

My file looks like:

X^~^12^d
X^~^19^d
Y^~^5^d
Y^~^10^d
Y^~^11^d
Z^~^14^d

I need a script that will "group by" the first field and Concatenate the values.

My output should be:

X^~^12,19^d
Y^~^5,10,11^d
Z^~^14~d

Does anyone have any idea ?
  #2 (permalink)  
Old 06-21-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Your post is on similiar lines to that of

shell script comparing files in a file

Check it out.


vino
  #3 (permalink)  
Old 06-21-2005
hellsd hellsd is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 20
thank for the example but it doesn't handle

where the delimiter is ^ and if the concatenated field is not last.

Any idea ?
  #4 (permalink)  
Old 06-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
something to start with:

nawk -f hell.awk file.txt

hell.awk:
Code:
BEGIN { FS=OFS="^" }
{
    arr[$1] = ($1 in arr) ? arr[$1] "," $3 : $3
}
END {
  for (i in arr)
    print i OFS "~", arr[i]
}
  #5 (permalink)  
Old 06-21-2005
hellsd hellsd is offline
Registered User
  
 

Join Date: Nov 2004
Posts: 20
Thanks!!! Can I Marry You ? :-)

you are the best
  #6 (permalink)  
Old 06-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by hellsd
you are the best
take a number....
glad to be of help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0