Sponsored Content
Full Discussion: MATRIX to CSV
Top Forums Shell Programming and Scripting MATRIX to CSV Post 302823763 by Yoda on Wednesday 19th of June 2013 08:41:11 PM
Old 06-19-2013
Not sure if this can be done much simpler, anyway here is an awk approach:
Code:
awk -F, '
        BEGIN {
                print "SUPERUSER,relatedUSER,TOTFrequencyrelations,(1)Frequency,(0)Frequency,(-1)Frequency,VALUE"
                OFMT = "%.1f"
        }
        NR > 1 {
                U[$2]
                U[$3]
                U[$4]
                R[$2","$3]++
                R[$2","$4]++
                R[$3","$2]++
                R[$3","$4]++
                R[$4","$2]++
                R[$4","$3]++
                if ( $1 > 0 )
                {
                        P[$2","$3]++
                        P[$2","$4]++
                        P[$3","$2]++
                        P[$3","$4]++
                        P[$4","$2]++
                        P[$4","$3]++
                }
                if ( $1 == 0 )
                {
                        N[$2","$3]++
                        N[$2","$4]++
                        N[$3","$2]++
                        N[$3","$4]++
                        N[$4","$2]++
                        N[$4","$3]++
                }
                if ( $1 < 0 )
                {
                        L[$2","$3]++
                        L[$2","$4]++
                        L[$3","$2]++
                        L[$3","$4]++
                        L[$4","$2]++
                        L[$4","$3]++
                }
        }
        END {
                for ( k in U )
                {
                        for ( l in R )
                        {
                                split ( l, V )
                                if ( V[1] == k )
                                {
                                        p = P[l] ? P[l] : 0
                                        n = N[l] ? N[l] : 0
                                        z = L[l] ? L[l] : 0
                                        print V[1], V[2], R[l], p, n, z, ( ( p + z ) > 0 ? ( p - z ) / ( p + z ) : 0 )
                                }
                        }
                }
        }
' OFS=, file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

diagonal matrix to square matrix

Hello, all! I am struggling with a short script to read a diagonal matrix for later retrieval. 1.000 0.234 0.435 0.123 0.012 0.102 0.325 0.412 0.087 0.098 1.000 0.111 0.412 0.115 0.058 0.091 0.190 0.045 0.058 1.000 0.205 0.542 0.335 0.054 0.117 0.203 0.125 1.000 0.587 0.159 0.357... (11 Replies)
Discussion started by: yifangt
11 Replies

2. Shell Programming and Scripting

2 problems: Mailing CSV file / parsing CSV for display

I have been trying to find a good solution for this seemingly simple task for 2 days, and I'm giving up and posting a thread. I hope someone can help me out! I'm on HPUX, using sqlplus, mailx, awk, have some other tools available, but can't install stuff that isn't already in place (without a... (6 Replies)
Discussion started by: soldstatic
6 Replies

3. Ubuntu

How to convert full data matrix to linearised left data matrix?

Hi all, Is there a way to convert full data matrix to linearised left data matrix? e.g full data matrix Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7 Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245 Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Discussion started by: evoll
8 Replies

4. Shell Programming and Scripting

awk? adjacency matrix to adjacency list / correlation matrix to list

Hi everyone I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row... (5 Replies)
Discussion started by: stonemonkey
5 Replies

5. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

6. Shell Programming and Scripting

Perl search csv fileA where two strings exist on another csv fileB

Hi I have two csv files, with the following formats: FileA.log: Application, This occured blah Application, That occured blah Application, Also this AnotherLog, Bob did this AnotherLog, Dave did that FileB.log: Uk, London, Application, datetime, LaterDateTime, Today it had'nt... (8 Replies)
Discussion started by: PerlNewbRP
8 Replies

7. Shell Programming and Scripting

3 column .csv --> correlation matrix; awk, perl?

Greetings, salutations. I have a 3 column csv file with ~13 million rows and I would like to generate a correlation matrix. Interestingly, you all previously provided a solution to the inverse of this problem. Thread title: "awk? adjacency matrix to adjacency list / correlation matrix to list"... (6 Replies)
Discussion started by: R3353
6 Replies

8. Shell Programming and Scripting

Comparing 2 CSV files and sending the difference to a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 ... (1 Reply)
Discussion started by: Naresh101
1 Replies

9. Shell Programming and Scripting

Compare 2 csv files in ksh and o/p the difference in a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 The... (7 Replies)
Discussion started by: Naresh101
7 Replies

10. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies
uhd_cal_tx_dc_offset(1) 					   User Commands					   uhd_cal_tx_dc_offset(1)

NAME
uhd_cal_tx_dc_offset - Generate TX DC Offset Calibration Table DESCRIPTION
The Universal Software Radio Peripheral Hardware Drivers handle calibration information. This application sets up Transmitter calibration for a daughterboard installed on the USRP. Because it also uses the receive side of the daughterboard, this application only handles trans- ceiver daughterboards. USRP Generate TX DC Offset Calibration Table Allowed options: --help help message --verbose enable some verbose --args arg device address args [default = ""] --tx_wave_freq arg (=507123) Transmit wave frequency in Hz --tx_wave_ampl arg (=0.69999999999999996) Transmit wave amplitude in counts --rx_offset arg (=934400) RX LO offset from the TX LO in Hz --freq_start arg Frequency start in Hz (do not specify for default) --freq_stop arg Frequency stop in Hz (do not specify for default) --freq_step arg (=7300000) Step size for LO sweep in Hz --nsamps arg (=10000) Samples per data capture This application measures leakage between RX and TX on an XCVR daughterboard to self-calibrate. SEE ALSO
uhd_cal_rx_iq_balance(1) uhd_cal_tx_iq_balance(1) UHD
March 2012 uhd_cal_tx_dc_offset(1)
All times are GMT -4. The time now is 09:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy