grep /home/test.log * |tail -1 | awk -F'[:,]' '{for(i=1;i<=NF;i++){if($i~/offset/){print $(i+1)}}}'
//这个命令将按照“:”和“,”作为字段分隔符,然后遍历各个字段,找到包含"offset"的字段,并打印出它的值。
test.log内容为:
{"k":"filebeat::logs::native::25560147-2057","v":{"id":"native::25560147-2057","prev_id":"","offset":262052629,"identifier_name":"native","source":"/home/test.log","timestamp":[2062251081368,1705139888],"ttl":172800000000000,"type":"log","FileStateOS":{"inode":25560147,"device":2057}}}