Sponsored Content
Top Forums Shell Programming and Scripting How to transpose a table of data using awk Post 302219373 by summer_cherry on Monday 28th of July 2008 11:43:10 PM
Old 07-29-2008
A perl script to transpose a metrix, hope it can address your issue.

Code:
$file=shift;
open(FH,"<$file") or die "can not open file";
while(<FH>){
        $_=~ tr/\n//d;
        @arr=split(",",$_);
        $col=$#arr;
        for($i=0;$i<=$#arr;$i++){
                $index=sprintf("%s%s",$.,$i);
                $hash{$index}=$arr[$i];
        }
        $row=$.;
}
close(FH);
for($a=0;$a<=$col;$a++){
        for($b=1;$b<=$row;$b++){
                $t=sprintf("%s%s",$b,$a);
                print $hash{$t},",";
        }
        print "\n";
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to transpose data elements in awk

Hi, I have an input data file :- Test4599,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,2,Rain Test90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,Not Rain etc.... I wanted to transpose these data to:-... (2 Replies)
Discussion started by: ahjiefreak
2 Replies

2. Shell Programming and Scripting

Transpose data from columns to lines for each event

Hi everyone, Maybe somebody could help me with this. I have a text file showing in 2 columns registers of services used by customers in a comercial place. The register for the use of any particular service begins with "EVENT" in column 1. I would like to transpose the info for each... (20 Replies)
Discussion started by: cgkmal
20 Replies

3. Shell Programming and Scripting

Transpose Data from Columns to rows

Hello. very new to shell scripting and would like to know if anyone could help me. I have data thats being pulled into a txt file and currently have to manually transpose the data which is taking a long time to do. here is what the data looks like. Server1 -- Date -- Other -- value... (7 Replies)
Discussion started by: Mikes88
7 Replies

4. Shell Programming and Scripting

Transpose Column of Data to Rows

I can no longer find my commands, but I use to be able to transpose data with common fields from a single column to rows using a command line. My data is separated as follows: NAME=BOB ADDRESS=COLORADO PET=CAT NAME=SUSAN ADDRESS=TEXAS PET=BIRD NAME=TOM ADDRESS=UTAH PET=DOG I would... (7 Replies)
Discussion started by: docdave78
7 Replies

5. Shell Programming and Scripting

Transpose data as rows using awk

Hi I have below requirement, need help One file contains the meta data information and other file would have the data, match the column from file1 and with file2 and extract corresponding column value and display in another file File1: CUSTTYPECD COSTCENTER FNAME LNAME SERVICELVL ... (1 Reply)
Discussion started by: ravlapo
1 Replies

6. Shell Programming and Scripting

Help with transpose data content

Hi, Below is my input file: c116_g1_i1 -,-,-,+ c118_g2_i1 +,+ c118_g3_i1 + c120_g1_i1 +,+,+,+ . . Desired Output File c116_g1_i1 - c116_g1_i1 - c116_g1_i1 - c116_g1_i1 + c118_g2_i1 + c118_g2_i1 + (3 Replies)
Discussion started by: perl_beginner
3 Replies

7. UNIX for Advanced & Expert Users

Transpose Messy Data

I have a messy, pipe-delimited ("|") input dataset. I would like to create a file of ID plus each component of field 4 which is delimited by ";" into a long, skinny shape for easier processing. A couple of complications are that field 4 may contain both commas and linefeed characters from the... (9 Replies)
Discussion started by: 91674io
9 Replies

8. UNIX for Beginners Questions & Answers

Transpose the data

Hi All, I have sort of a case to transpose data from rows to column input data Afghanistan|10000|1 Albania|25000|4 Algeria|25000|7 Andorra|10000|4 Angola|25000|47 Antigua and Barbuda|25000|23 Argentina|5000|3 Armenia|100000|12 Aruba|20000|2 Australia|50000|2 I need to transpose... (3 Replies)
Discussion started by: radius
3 Replies

9. UNIX for Beginners Questions & Answers

Transpose large data in UNIX

Hi I have the following sample of data: my full data dimention is 900,000* 1119 rs987435 C G 1 1 1 0 2 rs345783 C G 0 0 1 0 0 rs955894 G T 1 1 2 2 1 rs6088791 ... (7 Replies)
Discussion started by: marwah
7 Replies

10. Shell Programming and Scripting

Transpose table with awk

I am trying to format the table below to the output input: cand week sub1 sub2 sub3 sub4 joe 1 94.19 70.99 43.93 60.14 joe 2 94.07 51.02 41.07 38.92 joe 3 26.24 30.95 44.56 67.67 joe 4 72.36 60.92 40.78 83.25 joe 5 51 70.01 44.66 82.22... (7 Replies)
Discussion started by: aydj
7 Replies
mlib_MatrixMulSShift_U8_U8_Mod(3MLIB)			    mediaLib Library Functions			     mlib_MatrixMulSShift_U8_U8_Mod(3MLIB)

NAME
mlib_MatrixMulSShift_U8_U8_Mod, mlib_MatrixMulSShift_U8_U8_Sat, mlib_MatrixMulSShift_U8C_U8C_Mod, mlib_MatrixMulSShift_U8C_U8C_Sat, mlib_MatrixMulSShift_S8_S8_Mod, mlib_MatrixMulSShift_S8_S8_Sat, mlib_MatrixMulSShift_S8C_S8C_Mod, mlib_MatrixMulSShift_S8C_S8C_Sat, mlib_MatrixMulSShift_S16_S16_Mod, mlib_MatrixMulSShift_S16_S16_Sat, mlib_MatrixMulSShift_S16C_S16C_Mod, mlib_MatrixMulSShift_S16C_S16C_Sat, mlib_MatrixMulSShift_S32_S32_Mod, mlib_MatrixMulSShift_S32_S32_Sat, mlib_MatrixMulSShift_S32C_S32C_Mod, mlib_MatrixMulSShift_S32C_S32C_Sat - matrix multiplication by scalar plus shifting SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_MatrixMulSShift_U8_U8_Mod(mlib_u8 *z, const mlib_u8 *x, const mlib_u8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_U8_U8_Sat(mlib_u8 *z, const mlib_u8 *x, const mlib_u8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_U8C_U8C_Mod(mlib_u8 *z, const mlib_u8 *x, const mlib_u8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_U8C_U8C_Sat(mlib_u8 *z, const mlib_u8 *x, const mlib_u8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S8_S8_Mod(mlib_s8 *z, const mlib_s8 *x, const mlib_s8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S8_S8_Sat(mlib_s8 *z, const mlib_s8 *x, const mlib_s8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S8C_S8C_Mod(mlib_s8 *z, const mlib_s8 *x, const mlib_s8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S8C_S8C_Sat(mlib_s8 *z, const mlib_s8 *x, const mlib_s8 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S16_S16_Mod(mlib_s16 *z, const mlib_s16 *x, const mlib_s16 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S16_S16_Sat(mlib_s16 *z, const mlib_s16 *x, const mlib_s16 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S16C_S16C_Mod(mlib_s16 *z, const mlib_s16 *x, const mlib_s16 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S16C_S16C_Sat(mlib_s16 *z, const mlib_s16 *x, const mlib_s16 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S32_S32_Mod(mlib_s32 *z, const mlib_s32 *x, const mlib_s32 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S32_S32_Sat(mlib_s32 *z, const mlib_s32 *x, const mlib_s32 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S32C_S32C_Mod(mlib_s32 *z, const mlib_s32 *x, const mlib_s32 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); mlib_status mlib_MatrixMulSShift_S32C_S32C_Sat(mlib_s32 *z, const mlib_s32 *x, const mlib_s32 *c, mlib_s32 m, mlib_s32 n, mlib_s32 shift); DESCRIPTION
Each of these functions performs a multiplication of a matrix with a scalar and shifts the result. For real data, the following equation is used: z[i] = c[0]*x[i]*2**(-shift) where i = 0, 1, ..., (m*n - 1). For complex data, the following equation is used: z[2*i] = (c[0]*x[2*i] - c[1]*x[2*i + 1])*2**(-shift) z[2*i + 1] = (c[1]*x[2*i] + c[0]*x[2*i + 1])*2**(-shift) where i = 0, 1, ..., (m*n - 1). The ranges of valid shift are: 1 <= shift <= 8 for U8, S8, U8C, S8C types 1 <= shift <= 16 for S16, S16C types 1 <= shift <= 31 for S32, S32C types PARAMETERS
Each of the functions takes the following arguments: z Pointer to the destination matrix. x Pointer to the source matrix. c Pointer to the source scalar. When the function is used with complex data types, c[0] contains the scalar for the real part, and c[1] contains the scalar for the imaginary part. m Number of rows in each matrix. n Number of columns in each matrix. shift Right shifting factor. RETURN VALUES
Each of the functions returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_MatrixMulSShift_U8_Mod(3MLIB), attributes(5) SunOS 5.10 10 Nov 2004 mlib_MatrixMulSShift_U8_U8_Mod(3MLIB)
All times are GMT -4. The time now is 07:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy