Transposing X and Y axis of CSV data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Transposing X and Y axis of CSV data
# 1  
Old 02-28-2012
Java Transposing X and Y axis of CSV data

Hello list,

I have a source CSV data file as follows:
Code:
PC_NAME,MS11-040,MS11-039,MS11-038,MS11-035
abc123,Not Applicable,Not Applicable,Not Applicable,Not Applicable
abc987,Not Applicable,Not Applicable,Not Applicable,Not Applicable
tnt999,Not Applicable,Not Applicable,Applicable,Not Applicable
terminal,Installed,Installed,Installed,Installed

One thing to note is every time a new patch comes out, new field(s) of data will be appended to the source data field. And I am going to have to account for this.

What I am trying to achieve is reformat the data so that I have three fields:
Code:
<Patch_name>,<PC_Name>,<Applicable/Not/Installed>
MS11-040,abc123, Not Applicable
MS11-040,abc987, Not Applicable
MS11-040,tnt999, Not Applicable
MS11-040,terminal, Installed
etc...

Does anyone know of any python/perl/awk than could achieve this?

Any help would be appreciated.

Thanks

Land.

Last edited by Franklin52; 02-29-2012 at 03:16 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-28-2012
I think this might do it:

Code:
awk -F , '
    NR == 1 {    # capture list from the first line
        for( i = 2; i <= NF; i++ )
            pname[i-1] = $(i);
        next;
    }
    {        # apply each from first line to the current line
        for( i = 1; i <= length( pname ); i++ )
            printf( "%s,%s,%s\n", pname[i], $1, $(i+1) );
    }
' data-file-name |sort



This makes the assumption that there is only one set of data in the file.
This User Gave Thanks to agama For This Post:
# 3  
Old 02-28-2012
Fantastic, It works perfectly!
Thanks agama!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Transposing data based on 1st column

I do have a big tab delimited file of the following format aa 344 456 aa 34 67 bb 34 90 bb 23 100 bb 1 89 d 0 12 e 45 678 e 78 90 e 56 90 .... .... .... I would like to transpose the data based on the category on column one and get the output file in the following tab delimited... (8 Replies)
Discussion started by: Kanja
8 Replies

2. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

3. Shell Programming and Scripting

Problem creating graph with gnuplot with time on x-axis

Let me start by saying I'm new to gnuplot and not very good at unix at all.. Anyway, I'm each minute measuring temperature and humidity and saves the last 60 readings along with time in a textfile, values_minute. The contents of the file is formatted like this: time temperature humidity ... (8 Replies)
Discussion started by: hakro807
8 Replies

4. Shell Programming and Scripting

Transposing lines in a csv file with sed

Hi I have a large csv file with lines like below Date,Status,orig,dest,in,out,when,where 2012-01-01 00:30:37,I,48,56,23,98,83,34 2012-06-17 15:00:38,I,72,43,12,65,34,12I will really appreciate if someone can help with a sed script to transpose this to 2012-01-01 00:30:37,I,orig,48... (5 Replies)
Discussion started by: kaf3773
5 Replies

5. Shell Programming and Scripting

Difficult transposing of data from profiles blocks

Hello to all, I really hope some expert or awk guru could help me with this. I don't have how to begin and hope is not so difficult for somebody. I'll expecting how someone could resolve this problem I have to parse this. I have blocks of parameters for each MSISDN and I would like to extract... (9 Replies)
Discussion started by: Ophiuchus
9 Replies

6. Shell Programming and Scripting

Converting variable space width data into CSV data in bash

Hi All, I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for. My Input data in inputfile.txt 19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Discussion started by: vharsha
4 Replies

7. Shell Programming and Scripting

Help for a Perl newcomer! Transposing data from columns to rows

I have to create a Perl script which will transpose the data output from my experiment, from columns to rows, in order for me to analyse the data. I am a complete Perl novice so any help would be greatly appreciated. The data as it stands looks like this: Subject Condition Fp1 ... (12 Replies)
Discussion started by: Sarah_W
12 Replies

8. UNIX for Dummies Questions & Answers

Transposing data output

Hi, I've just created a shell script that produces the following output: hd1 hd3 hd9 /optnonaix/esp /optnonaix/app/oracle /u06 (564.67) (675.97) (678.90) I would like the output to be as hd1 /optnonaix/esp (564.67) hd3 /optnonaix/app/oracle (675.97) hd9 /u06 (678.90) Need some... (2 Replies)
Discussion started by: bazzabogan
2 Replies

9. OS X (Apple)

Adjust X & Y screen axis

I'm using my wife's Macbook, and I just noticed that her screen is off axis, but I can't find a way to adjust it. I've tried playing around with resolution in preferences, but nothing. Maybe a terminal command for adjusting the x and y values of the screen? Any and all suggestions welcomed :) (2 Replies)
Discussion started by: andou
2 Replies

10. AIX

Add printer connected to a axis printserver

Hi guys, I have a AIX 4.3 system, and I need to configure a printer, but that printer it's connected to a axis print server. I have lot of years working with unix, but never added a printer in a AIX system. I need to add using "remote print queue", and add the hostname and ip to the /etc/hosts?... (2 Replies)
Discussion started by: uadm26
2 Replies
Login or Register to Ask a Question