1

I have about 150 files containing 3 columns of x, y, z values and no header.

x1 y1 z1

x2 y2 z2

x3 y3 z3

...

xn yn zn

For our compress sensing algorithm, I need to have these values in one column only

x1

y1

z1

x2

y2

z2

. . .

xn

yn

zn

How could I perform this batch operation for 150 files, without using MatLab? From my previous question, I believe this could be done by using sed. But batch processing 150 files effectively is beyond my ability. I am running on Win7 with cygwin installed. Any suggestion would be appreciated.

Thank you for your help.

Regards,

ikel

Edit: The delimiter is TAB

Community
  • 1
  • 1
ikel
  • 518
  • 2
  • 6
  • 27

1 Answers1

2

Assuming you only have the files of interest in your present working directory, and, that the delimiter of your files is a single space, and, that you have GNU sed installed:

sed -i 's/ /\n/g' *

Alternatively, you could avoid sed and use tr and a for loop, like this:

for i in file*; do tr " " "\n" < "$i" > "$i.bak" && mv "$i.bak" "$i"; done
Steve
  • 51,466
  • 13
  • 89
  • 103
  • The delimiter happens to be a tab. That means I have to use `^I` instead of `s`? All files are in the same directory. – ikel Jan 25 '13 at 09:53
  • 1
    For a tab, use: `s/\t/\n/g`, which means substitute a tab for a newline, globally. – Steve Jan 25 '13 at 09:59