【发布时间】:2020-03-11 19:21:33
【问题描述】:
我有一个包含 150 万个文本文件的目录,其内容如下:
TDB_TCFE9:
POLY version 3.32
POLY:POLY:POLY:POLY:POLY: Using global minimization procedure
Calculated 71400 grid points in 1 s
Found the set of lowest grid points in 1 s
Calculated POLY solution 11 s, total time 13 s
POLY: VPV(LIQUID)=0
POLY:POLY:POLY:POLY:POLY:POLY: Using global minimization procedure
Calculated 71400 grid points in 1 s
Found the set of lowest grid points in 0 s
Calculated POLY solution 5 s, total time 6 s
POLY: *** STATUS FOR ALL PHASES
文件被命名为id1.TCM.log。只有idchanges 之后的数字。
我想要做的是 grep VPV(LIQUID)= 之后的值并将这个值提供给 x1 然后 x2。
如果x2大于0.0001,则将对应的文件移动到目录with_liquid。如果没有,什么也不做。
我使用的代码是
for j in `seq 1500000`
do
echo ${j}
x1=`grep -a VPV\(LIQUID\) id${j}.TCM.log |sed s/POLY_3://g|awk 'BEGIN{FS="="}{print $2}'|tail -1`
x2=$(printf "%.14f" $x1)
if [ $(echo "$x2 > 0.0001"| bc -l) -eq 1 ]; then
mv id${j}.TCM.log with_liquid
fi
done
效果很好。唯一的问题是耗时太长。我怎样才能做得更快?我也对 python 代码或任何其他解决方案持开放态度。
非常感谢。
【问题讨论】:
-
您是否考虑过使用多处理来利用所有 CPU 内核?
-
@Chris 我对此持开放态度,但不知道该怎么做。
-
每个文件都只有示例那么大吗?