clean up the header of csv files with awk

Viewed 415

I have a bunch of csv files that look like this:

Time,Channel A
(s),(V)

0.00000000,0.58058560
0.00666667,0.58913630
0.01333334,0.58058560

And I want to transform it to:

Time (s),Channel A (V)
0.00000000,0.58058560
0.00666667,0.58913630
0.01333334,0.58058560

The units are not necessarily identical across files (i.e. there might be (ms),(µV) etc.)

I got as far as removing the blank line (which is always line no. 3) with awk 'FNR!=3' but cutting the 2nd row arguments and pasting them behind the first row fields is beyond my capacity ;(

Please help me out! Motivation: there are lots of these files. Doing it by hand is not feasible…

EDIT: First of all: thanks for helping me out. As there seems to be the same issue with 2 of your answers, there might be a problem in my file potentially? I suspect the empty line to somehow cause trouble?

  • the shell-script gives me the error 'xpected empty line, read '
  • the perl-script and the awk-script give me a faulty first line:

     (V) (s),Channel A
    0.00000000,0.58058560
    

If it helps, I uploaded a sample infile.

4 Answers
Related