![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| merging similar lines | adambot | Shell Programming and Scripting | 2 | 05-05-2009 03:52 PM |
| Urgent help needed on merging lines with similar words | awb221 | Shell Programming and Scripting | 3 | 02-23-2009 11:16 PM |
| Merging two command into single line | kingganesh04 | UNIX for Advanced & Expert Users | 2 | 02-04-2009 09:45 AM |
| Merging columns from multiple files in one file | isgoed | Shell Programming and Scripting | 1 | 08-03-2008 09:54 PM |
| merging few columns of two text files to a new file | kolvi | Shell Programming and Scripting | 4 | 09-15-2005 04:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
merging similar columns in a single line file
Hi Guys. I have tried the commands sort and join. But I couldn't able to to find the command for joining in a single line based on keys.My example inputs and outputs are like the following.
Help would be appreciated. ![]() Input file a1tabXXXXXXX a2tabXXXXXXX a6tabYYYYYYYYY a71tabXXXXXXX a62tabYYYYYYYYY a30tabZZZZZ a13tabZZZZZ a43tabZZZZZ a23tabZZZZZ outputfile XXXXXXXtaba1taba2taba71 YYYYYYYYYtaba6taba62tab ZZZZZtaba30taba13taba43tab23 |
| Bits Awarded / Charged to repinementer for this Post | |||
| Date | User | Comment | Amount |
| 05-28-2009 | nshailesh | N/A | 24 |
|
||||
|
you should put in some effort next time by showing what you have done
If you have Python Code:
#!/usr/bin/env python
d={}
for line in open("file"):
line=line.strip().split()
d.setdefault(line[-1],[])
d[line[-1]].append(line[0])
for i,j in d.iteritems():
print i, '\t'.join(j)
Code:
YYYYYYYYY a6 a62 ZZZZZ a30 a13 a43 a23 XXXXXXX a1 a2 a71 |
|
||||
|
Yep
Thanx Guys the both scripts working great.
Well ghost Dog I tried to write script in perl but the sript was giving funny values and wasted 3 hrs. I didn't want to put the scipt coz that sript doesn't make any sense. But thanx for the advice |
|
|||||
|
Quote:
Code:
$
$ perl -ne 'split; $x{$_[1]}=$x{$_[1]}."\t".$_[0]; END{foreach $k(keys %x){print $k,"\t",$x{$k},"\n"}}' input.txt
XXXXXXX a1 a2 a71
ZZZZZ a30 a13 a43 a23
YYYYYYYYY a6 a62
$
$
Amazon.com Message Cheers, tyler_durden ![]() |
| Bits Awarded / Charged to durden_tyler for this Post | |||
| Date | User | Comment | Amount |
| 05-28-2009 | vidyadhar85 | Great quote!! | 1,000 |
|
||||
|
cool
Awesome Tyler
Last edited by repinementer; 05-28-2009 at 04:26 AM.. |
| Sponsored Links | ||
|
|