批处理-在不使用MatLab的情况下将3列x,y,z值合并为1列 [英] Batch - combining 3 columns of x, y, z values into 1 column without using MatLab
问题描述
我大约有150个文件,其中包含3列x,y,z值,并且没有标题.
I have about 150 files containing 3 columns of x, y, z values and no header.
x1 y1 z1
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
如何在不使用MatLab的情况下对150个文件执行此批处理操作?根据我之前的问题,我相信这可能是使用 sed 完成.但是有效地批处理150个文件超出了我的能力范围.我在装有cygwin的Win7上运行. 任何建议将不胜感激.
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.
谢谢您的帮助.
此致
ikel
定界符为TAB
推荐答案
假定您在当前工作目录中仅拥有感兴趣的文件,并且文件的定界符为单个空格,并且您具有GNU sed
已安装:
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' *
或者,您可以避免sed
并使用tr
和for
循环,如下所示:
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
这篇关于批处理-在不使用MatLab的情况下将3列x,y,z值合并为1列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!