[英]bash script optimization for big data
I have the follogwing litte Skript that forms date.我有 forms 日期的以下小脚本。 The Problem i face is that the Skript is used for big data log files and it takes far to long.
我面临的问题是 Skript 用于大数据日志文件,并且需要很长时间。 I changed the for loop from read to cat because its faster.
我将 for 循环从 read 更改为 cat 因为它更快。 But the data program is still far to slow.
但数据计划的速度仍然很慢。 How can I improve this?
我该如何改进呢?
IFS='
'
for i in $(cat ist.log | egrep -o "^.{19}"); do
olddatum=${i}
newdatum=`date -d "${olddatum}" +'%b %e %T'`
echo ${newdatum} >> soll.log.fixed
done
With the shell and sed
and the date
utility (most probably GNU date
)使用 shell 和
sed
和date
实用程序(很可能是 GNU date
)
#!/bin/sh
search=$(sed "s/^\(.\{19\}\).*/\1/" file.txt)
replace=$(date -d "$search" '+%b %e %T')
sed "s/^$seach/$replace /" file.txt
With a while read loop using the shell.使用 shell 进行 while 读取循环。 Don't read lines with
for
不要用
for
阅读行
#!/usr/bin/env bash
while IFS= read -r lines; do
if [[ $lines =~ ^(.{19})(.+) ]]; then
printf '%s %s\n' "$(date -d "${BASH_REMATCH[1]}" +'%b %e %T')" "${BASH_REMATCH[2]}"
else
printf '%s\n' "$lines"
fi
done < file.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.