Bash-从GZIP文件中提取匹配的字符串运行非常缓慢

问题描述 投票:1回答:1

完成Bash中的新手。尝试通过1000个gzip文件进行迭代,可能是GNU并行解决方案?

#!/bin/bash
ctr=0
echo "file_name,symbol,record_count" > $1
dir="/data/myfolder"
for f in "$dir"/*.gz; do

  gunzip -c $f | while read line;
  do
    str=`echo $line | cut -d"|" -f1`
    if [ "$str" == "H" ]; then
      if [ $ctr -gt 0 ]; then
        echo "$f,$sym,$ctr" >> $1
      fi
      ctr=0
      sym=`echo $line | cut -d"|" -f3`
      echo $sym
    else
      ctr=$((ctr+1))
    fi
  done
done

任何帮助加快流程的工作将不胜感激!!

完成Bash中的新手。尝试通过1000个gzip文件进行迭代,可能是GNU并行解决方案? #!/ bin / bash ctr = 0 echo“ file_name,symbol,record_count”> $ 1 dir =“ / data / myfolder” for f in“ $ ...

bash parallel-processing gnu
1个回答
0
投票
#!/bin/bash
ctr=0
export ctr
echo "file_name,symbol,record_count" > $1
dir="/data/myfolder"
export dir

doit() {
  f="$1"
  gunzip -c $f | while read line;
  do
    str=`echo $line | cut -d"|" -f1`
    if [ "$str" == "H" ]; then
      if [ $ctr -gt 0 ]; then
        echo "$f,$sym,$ctr"
      fi
      ctr=0
      sym=`echo $line | cut -d"|" -f3`
      echo $sym >&2
    else
      ctr=$((ctr+1))
    fi
  done
}
export -f doit

parallel doit ::: *gz 2>&1 > $1 
© www.soinside.com 2019 - 2024. All rights reserved.