我想逐行从日志文件中提取时间戳和文件大小信息,每一行的格式如下:
34600--[30 / Apr / 1998:21:30:17 +0000]“ GET /images/hm_bg.jpg HTTP / 1.0” 200 24736
括号包含时间戳,最后一段“ 24736”代表文件大小。
谁能知道如何使用Shell脚本或其他语言吗?
尝试类似的东西
#!/bin/bash
while read -r line; do
[[ $line =~ '['(.*)']' ]] && echo "${BASH_REMATCH[1]} ${line##*' '}"
done < file
例如
> cat file
34600 - - [30/Apr/1998:21:30:17 +0000] "GET /images/hm_bg.jpg HTTP/1.0" 200 24736
> while read -r line; do [[ $line =~ '['(.*)']' ]] && echo "DATE=${BASH_REMATCH[1]} SIZE=${line##*' '}"; done < file
DATE=30/Apr/1998:21:30:17 +0000 SIZE=24736
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句