LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-04-2010, 10:20 PM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,153

Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
Combining records with same key


Hello.

I'm new to Linux and struggling to learn sed on my own. Therefore a sed solution is most desirable, but all advice will be gratefully accepted.

Input file (already sorted on the key field):
204 Daniel Barton
206 Mary Halston
206 David Coleman
206 Carson Coleman
207 Roland Highsmith
207 Annie Highsmith
209 Connie Ward

Desired output file:
204 Daniel Barton
206 Mary Halston David Coleman Carson Coleman
207 Roland Highsmith Annie Highsmith
209 Connie Ward

How may this be achieved? Thanks in advance.

Daniel B. Martin
 
Old 04-05-2010, 12:11 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,655

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Not sure in sed (and not sure the right tool), but this works:

Code:
awk '{ arr[$1] = arr[$1]" "$2" "$3 }END{ for (x in arr) print x arr[x]}' file
 
  


Reply

Tags
joining


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading caller detail records(CDR ) records eliufoo Linux - Networking 2 12-17-2008 12:31 AM
java: SQL duplicate key exception or query for key is faster kpachopoulos Programming 1 01-06-2008 05:32 AM
DNS Zone Records - MX Records ddzc Linux - Software 8 05-24-2007 02:26 PM
1+0 records in how to disiable in DD command "1+0 records out" Kotresh Linux - Software 3 03-08-2007 09:57 AM
Smart Key Signature ERRORS! How do I delete this bad key from my computer? Balarabay1 Linux - Software 4 09-27-2006 12:01 PM


All times are GMT -5. The time now is 06:32 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration