问题
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