Long to wide format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Long to wide format
# 1  
Old 11-20-2013
Long to wide format

hi, can you please help me convert my data

i have paired comparisons (col 3) in long format for 750 variables (col 1 and 2), i need to convert into wide format. the diagonal must be 0s, and the order doesnt matter.
My file is unsorted.

example input

Code:
A	B	34
A	88	45
A	A23	43
A23	B	4.5
A23	88	44
B	88	45

output

Code:
	A	B	88	A23
A	0	34	45	43
B	34	0	45	4.5
88	45	45	0	44
A23	43	4.5	44	0

# 2  
Old 11-20-2013
Try this:
Code:
awk '{
  a[$2,$1]=a[$1,$2]=$3
  l[$1];l[$2]
 }
 END {
  for (i in l) {
   printf "%10s", i
  }
  printf "\n"
  for (i in l) {
   printf "%-10s", i
   for (j in l) {
    printf "%-10s", a[i,j]?a[i,j]:0
   }
   printf "\n"
  }
 }' file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

System-wide search

When looking for wherever a program or a filename appears in the system, a short scrip is "findinner" which another script calls with a long parameter list consisting of path names ending with ".sh" or ".menu". "findinner" looks like this: # If not .savenn file, show name and result of grep. #... (4 Replies)
Discussion started by: wbport
4 Replies

2. AIX

World Wide Name (FLEX)

Does anyone know how to find the Worl Wide Name (WWN) on a IBM flex system ? (4 Replies)
Discussion started by: Tharsan
4 Replies

3. Shell Programming and Scripting

Long list file display different time format.

Hi Gurus, I have some weird issue. when using ls -l the result shows different time format: -rw-r--r-- 1 abc gourp1 3032605576 Jun 14 2013 abc -rw-rw-r-- 1 abc gourp1 1689948832 Aug 10 06:22 abc one display 2013 which is year; another one displays 06:22 which is time. ... (4 Replies)
Discussion started by: ken6503
4 Replies

4. Shell Programming and Scripting

modify ls -l (long listing format output) strictly using SED only straightforward goalhard 4 me doh

Below is a sample out of ls -l which I would like to rearrange or modify by field numbers for example I successfully managed to disect using simple paragraph however for ls -l I can't divide the rows or fields by field number. Successful modification by fields using SED sample: $ sed -e... (1 Reply)
Discussion started by: wolf@=NK
1 Replies

5. Shell Programming and Scripting

Validate long date format in If statement

Hi, I want to validate if the given input is a valid month (written in long month format) Jan / Feb / Mar / Apr / May / Jun etc etc This is what I've got with || (or statements): #!/usr/bin/ksh INPUT_DATE=$1 FORMATTED_DATE=`date | cut -f2 -d' '` #If there's no input use the... (1 Reply)
Discussion started by: Batsies
1 Replies

6. UNIX for Dummies Questions & Answers

city wide connection

what would be the best way to phyisically connect a series of computerised bus stops to a central computer in a city-wide network?? (3 Replies)
Discussion started by: spitfireuk1
3 Replies

7. UNIX for Dummies Questions & Answers

Terminal too wide

Hi Experts, It may be a trivial thing, but I am stuck. Whenver I try to open a file using vi I get error Terminal Too wide. I am using putty to connect to a Sun OS. Please advice. bash-2.05$ vi all_subs_ded_20080203.txt Terminal too wide :q 1 more file to edit:q (3 Replies)
Discussion started by: RishiPahuja
3 Replies

8. Shell Programming and Scripting

Help with find command and list in a long format each found file

The purpose of those comands are to find the newest file in a directory acvrdind to system date, and it has to be recursively found in each directory. The problem is that i want to list in a long format every found file, but the commands i use produce unexpected results ,so the output lists in a... (5 Replies)
Discussion started by: alexcol
5 Replies

9. Shell Programming and Scripting

ls -l output with long iso format

Hello everbody, I've a list of logfiles (transfer1.log, transfer2.log, ... transfer168.log.) Each of these was created at the end of the actual month and I've to write a script to calculate the utilisation ratio of the actual month of the system. I don't want to scan every logfile, so I've to... (1 Reply)
Discussion started by: rofflox
1 Replies
Login or Register to Ask a Question