The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
More than transposing! bulash UNIX Desktop for Dummies Questions & Answers 3 04-11-2008 02:20 PM
Transposing string unibboy Shell Programming and Scripting 3 02-13-2008 03:12 PM
Major Awk problems (Searching, If statements, transposing etc.) Blivo Shell Programming and Scripting 2 09-05-2007 03:41 AM
file transposing mskcc Shell Programming and Scripting 24 08-04-2005 08:23 AM
transposing letters myscsa2004 Shell Programming and Scripting 4 05-12-2004 07:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 09-15-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
i dunno the syntax in sun/solaris. i got the same result as yours.
Reply With Quote
Forum Sponsor
  #9  
Old 09-15-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
Quote:
Originally Posted by anbu23
i dunno the syntax in sun/solaris. i got the same result as yours.
you mean these results?
Code:
2 3 4
3 0 7 9
1 5 6 7
if that's the case, do you think that's what the OP wanted?
Reply With Quote
  #10  
Old 09-15-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,580
alternatively in Python:

Code:
store = {} 
all = open("datafile.txt").readlines()
for items in all:
 	key,value = items.split()
  	if store.has_key(key):
 		store[key].append(value)
 	else:
 		store[key] = [value]

for i in sorted(store.keys()):
 	print i, ' '.join(store[i])
Output:

Code:
1 5 6 7
2 3 4
3 7 0 9
Reply With Quote
  #11  
Old 09-15-2006
Registered User
 

Join Date: Jul 2005
Posts: 137
Ruby:
Code:
h = Hash.new{[]}
while line = gets
  k,v = line.split
  h[k] <<= v
end
puts h.sort.map{|a| a.join " "}
Reply With Quote
  #12  
Old 09-16-2006
Registered User
 

Join Date: Aug 2006
Posts: 30
Thumbs up just another simple soln

Code:
for i in `awk '{print $1}' file | uniq`
do
        echo $i `grep $i file | awk '{print $2}'`
done
hope this helps.........

cheers,
sayon
Reply With Quote
  #13  
Old 09-16-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
Originally Posted by sayonm
Code:
for i in `awk '{print $1}' file | uniq`
do
        echo $i `grep $i file | awk '{print $2}'`
done
hope this helps.........

cheers,
sayon
tried with sample modified input and it would fail,

Code:
>cat s
1 5
1 6
1 7
2 3
2 4
3 7
3 0
3 9
11 2
11 0
Code:
>echo 1 `grep 1 s | awk '{print $2}'`
5 6 7 2 0
a slight modification to script
Code:
for i in `awk '{print $1}' s | uniq`
do
  awk -F" " 'BEGIN{x='$i'} { if( $1=='$i' ) x=x" "$2} END{print x}' s
done
Code:
>newoutput
1 5 6 7
2 3 4
3 7 0 9
11 2 0
Reply With Quote
  #14  
Old 09-16-2006
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by sayonm
Code:
for i in `awk '{print $1}' file | uniq`
do
        echo $i `grep $i file | awk '{print $2}'`
done
hope this helps.........

cheers,
sayon
your script will be slower compared to one done in memory..just my opinion

anyway, for the sample input data, i got

1 5 6 7
2 3 4
3 3 7 0 9
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0