1

I have mastered tips at "Probably grep, but still do not get how to read row in file1 and paste it as a column in file2" question and came with another one, this is a good one : )

I have a csv file1 like this:

Aname,4.999165E-08,5.99986E-08,7.000066E-08,8.000618E-08,8.999692E-08,9.998538E-08,1.099699E-07,1.199585E-07,1.199579E-07,1.299462E-07,1.349502E-07,1.3495E-07,1.349501E-07,1.349503E-07,2.000009E-07,2.999739E-07,
Bname,2.269E-05,3.902E-05,6.580E-05,9.907E-05,1.419E-04,1.930E-04,2.530E-04,3.212E-04,3.284E-04,4.090E-04,4.505E-04,4.672E-04,4.294E-04,4.590E-04,1.257E-03,2.794E-03, 
Cname,487.3,484.8,482.7,480.9,479.2,477.9,476.7,475.6,475.4,474.6,474.2,473.8,474.1,473.6,469.5,466.1,

It is a file with three rows(Aname,Bname,Cname) and I am trying to output these rows into parallel columns in file2, that should look like this:

[1]: http://oi41.tinypic.com/i6h1jt.jpg Should look like

As far as I managed to get is this:

[2]: http://oi41.tinypic.com/35ncxtt.jpg What I'm getting

Is it possible to solve this???

I am using commands cat somefile.csv | grep 'Aname' > file1.csv, for creating file1 with Aname row<

and cat someanotherfile.csv | grep 'Bname' >> file1.csv for adding additional rows to file1

and then for making columns cat file1.csv | tr ',' '\n' > file2

I hope it is clear enough : )

Thor
  • 45,082
  • 11
  • 119
  • 130
Mod3
  • 15
  • 2
  • maybe anybody knows if this thing (changing order of row/column data) has a special name or smt., it would help me to google it easier... – Mod3 Nov 15 '13 at 12:02
  • This process is called transposing. There are some good examples at [Transpose a file in bash](http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash). – Thor Nov 15 '13 at 13:08

1 Answers1

1
paste <(awk -F , '/Aname/{for(i=1;i<=NF;i++) print $i,","}' file.csv) <(awk -F , '/Bname/{for(i=1;i<=NF;i++) print $i,","}' file.csv) <(awk -F , '/Cname/{for(i=1;i<=NF;i++) print $i}' file.csv) 
MC ND
  • 69,615
  • 8
  • 84
  • 126