我有这个字符串:
14-Nov-2018 10:14:44.775 client IP1#59098: view internal: query: DOMAIN IN A + (IP2)
我想解析它以删除小时中的分钟和秒。结果将是下一个:
14-Nov-2018 10 client IP1#59098: view internal: query: DOMAIN IN A + (IP2)
我是从文件中获取此字符串的,所以如果用管道来实现,那将是完美的。我当前的行如下:
cat $dns_logs | grep "$date" | HERE WOULD BE YOUR SOLUTION > $temp_queries
谢谢!
答案 0 :(得分:0)
sed -r 's/(:[0-9]{2}){2}\.[0-9]{3} //'
答案 1 :(得分:0)
如果您对awk
表示满意,那么请尝试以下。
echo "14-Nov-2018 10:14:44.775 client IP1#59098: view internal: query: DOMAIN IN A + (IP2)" |
awk '
match($0,/[0-9]+:[0-9]+:[0-9]+\.[0-9]+/){
print substr($0,1,RSTART-1),substr(substr($0,RSTART,RLENGTH),1,2),substr($0,RSTART+RLENGTH+1)
next
}
1'
答案 2 :(得分:0)
整行都可以完成
awk -v d="$date" '($0 ~ d){$2=substr($2,1,2); print}' "$dns_logs"