Batch - combining 3 columns of x, y, z values into 1 column without using MatLab

时光怂恿深爱的人放手 提交于 2019-12-23 03:02:18

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/14516935/batch-combining-3-columns-of-x-y-z-values-into-1-column-without-using-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!