从矩阵中的单元格中删除空格 [英] remove spaces from cells in matrix
问题描述
我有一个数字矩阵(5800行和350列).每个单元格都是
I have a matrix(5800 rows and 350 columns) of numbers. Each cell is either
0 / 0
1 / 1
2 / 2
删除每个单元格中所有空间的最快方法是:
What is the fastest way to remove all spaces in each cell, to have:
0/0
1/1
2/2
Sed,R,能做到最快的任何事情.
Sed, R, anything that will do it fastest.
推荐答案
如果您要提高效率,则应该使用coreutils tr来完成这样一个简单的任务:
If you are going for efficiency, you should probably use coreutils tr for such a simple task:
tr -d ' ' < infile
我使用GNU awk,GNU sed,perl v5.14.2和GNU coreutils v8.13将发布的答案与300K文件进行了比较.每个测试运行了30次,这是平均值:
I compared the posted answers against a 300K file, using GNU awk, GNU sed, perl v5.14.2 and GNU coreutils v8.13. The tests were each run 30 times, this is the average:
awk - 1.52s user 0.01s system 99% cpu 1.529 total
sed - 0.89s user 0.00s system 99% cpu 0.900 total
perl - 0.59s user 0.00s system 98% cpu 0.600 total
tr - 0.02s user 0.00s system 90% cpu 0.020 total
所有睾丸都按上述(cmd < infile
)运行,并且输出定向到/dev/null.
All testes were run as above (cmd < infile
) and with the output directed to /dev/null.
这篇关于从矩阵中的单元格中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!