Another transposing issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Another transposing issue
# 8  
Old 09-15-2006
i dunno the syntax in sun/solaris. i got the same result as yours.
# 9  
Old 09-15-2006
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?
# 10  
Old 09-15-2006
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

# 11  
Old 09-16-2006
Ruby:
Code:
h = Hash.new{[]}
while line = gets
  k,v = line.split
  h[k] <<= v
end
puts h.sort.map{|a| a.join " "}

# 12  
Old 09-16-2006
MySQL 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......... Smilie

cheers,
sayon
# 13  
Old 09-16-2006
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......... Smilie

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

# 14  
Old 09-16-2006
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......... Smilie

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

transposing lines to columns

Okay folks, here's a question. I tried searching but couldn't find exactly what I needed. I have a text file (excerpt below). This text file is an extract I did from several hundred pages of datasheets using grep so I could look only at the site history for each site. The problem is that... (2 Replies)
Discussion started by: jbrandt1979
2 Replies

2. Shell Programming and Scripting

transposing columns into rows

Hi, I need to transpose columns of my files into rows and save it as individual files. sample contents of the file below. 0.9120 0.7782 0.6959 0.6904 0.6322 0.8068 0.9082 0.9290 0.7272 0.9870 0.7648 0.8053 0.8300 0.9520 0.8614 0.6734 0.7910 0.6413 0.7126 0.7364 0.8491 0.8868 0.7586 0.8949... (8 Replies)
Discussion started by: ida1215
8 Replies

3. Shell Programming and Scripting

Transposing a file

Hi Guys, I have file containing this kind of format below: ======== MOBILITY EVENT (G): ATTACH REJECT ========= Time : <date_time> Node : <node> GMM Cause : <code> Details : <details> Attach : <attach type> IMSI : <imsi> PTMSI : <ptmsi> RA New : <ra new> RA... (9 Replies)
Discussion started by: rymnd_12345
9 Replies

4. Shell Programming and Scripting

Transposing columns with awk

I want a sweet simple time efficient awk script in online which gets output 001_r 0.0265185 0.0437049 0.0240642 0.0310264 0.0200482 0.0146746 0.0351344 0.0347856 0.036119 1.49 firstcoloumnvalue allvaluesof 'c' in one row 001_r : 002_r c: 0.0265185 N: 548 001_r : 007_r c:... (5 Replies)
Discussion started by: phoenix_nebula
5 Replies

5. Shell Programming and Scripting

Transposing a file

Hi All, I have a input file say FILEA. FILEA -------- empid1 sal1 location1 manager1 empid2 sal2 location2 manager2 empid3 sal3 location3 manager3 . . . (3 Replies)
Discussion started by: 46019
3 Replies

6. Shell Programming and Scripting

Transposing a file

i have a file as: 1 2 3 4 5 i want output as : 1 2 3 4 5 can anybody help on this?? (14 Replies)
Discussion started by: vikas_kesarwani
14 Replies

7. UNIX Desktop Questions & Answers

More than transposing!

Hi everyone, I have a poblem like that: I have a file which includes data looks like: 0.65214 0.3597 1.0 0.65244 0.3502 1.0 0.65273 0.3553 1.0 0.65305 0.3544 1.0 0.65327 0.3505 1.0 0.65359 0.3516 1.0 0.65578 0.6464 1.0 0.65605 0.6453 1.0 0.65633 0.6437 1.0 0.65660 0.6488 1.0... (3 Replies)
Discussion started by: bulash
3 Replies

8. Shell Programming and Scripting

Transposing string

Hello guys, can some please give driection as to how to archieve this big issue i am having: I a random number that has been generated and wants the user to guess it, let me illustrate this: say the random i hve generated is 'nice' - i then hide it from the user and display it in ----... (3 Replies)
Discussion started by: unibboy
3 Replies

9. Shell Programming and Scripting

file transposing

Hello, Is there a way to transpose a file in shell scripting? For instance, from a1 a2 a3 a4 a5 a6 a7 .... b1 b2 b3 b4 b5 b6 b7 .... c1 c2 c3 c4 c5 c6 c7 .... d1 d2 d3 d4 d5 d6 d7 ... ... ... ... to a1 b1 c1 d1 .... a2 b2 c2 d2 .... a3 b3 c3 d3 .... a4 b3 c3 d4 .... ... ... (24 Replies)
Discussion started by: mskcc
24 Replies

10. Shell Programming and Scripting

transposing letters

Hi, I've written a shell function in bash that reads letters into an array, then outputs them in one column with: for n in "${array}"; do echo $n done I was wondering if anyone knew how i would transpose the letters that are output by the for loop. Right now my output is: aabbcc... (4 Replies)
Discussion started by: myscsa2004
4 Replies
Login or Register to Ask a Question