LinuxQuestions.org
Review your favorite Linux distribution.
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, 09:20 PM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,879

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
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-04-2010, 11:11 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
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-16-2008 11:31 PM
java: SQL duplicate key exception or query for key is faster kpachopoulos Programming 1 01-06-2008 04:32 AM
DNS Zone Records - MX Records ddzc Linux - Software 8 05-24-2007 01:26 PM
1+0 records in how to disiable in DD command "1+0 records out" Kotresh Linux - Software 3 03-08-2007 08:57 AM
Smart Key Signature ERRORS! How do I delete this bad key from my computer? Balarabay1 Linux - Software 4 09-27-2006 11:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:23 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration