1

Looking for a help to extract the data from the below log file.

Log data:

INFO  : Partition test.t_abc_cdfn_gprs{schdate_year=2016, schdate_month=02, schdate_day=17, schtime_hour=01} stats: [numFiles=0, numRows=4265004, totalSize=0, rawDataSize=0]
INFO  : Partition test.t_abc_glob_gprs{year=2016, month=02, day=17} stats: [numFiles=0, numRows=4265004, totalSize=0, rawDataSize=0]
INFO  : Partition test.t_abc_part_gprs{part1=2016, part2=02} stats: [numFiles=0, numRows=4265004, totalSize=0, rawDataSize=0]*

Code:

echo "INFO  : Partition test.t_abc_cdfn_gprs{schdate_year=2016, schdate_month=02, schdate_day=17, schtime_hour=16} stats: [numFiles=0, numRows=16123348, totalSize=0, rawDataSize=0]" | sed -n '/{/{s/.*{//;s/\}/,/;p}' | awk -F':' '{print $1}' | sed 's/stats//g' | sed 's%,%/%g'

The value I need to extract can be only Year/month/day or even it may be different format also mentioned in sample log entry, But the values will be enclosed by curly braces and variable in front like schdate=2016, etc...

Output Required:

2016/02/17/01
2016/02/17
2016/02
Cyrus
  • 84,225
  • 14
  • 89
  • 153
William R
  • 739
  • 2
  • 13
  • 34

1 Answers1

0

With GNU sed:

sed 's/.*{\(.*\)}.*/\1/;s/[^= ]\+=//g;s/, /\//g' file 

Output:

2016/02/17/01
2016/02/17
2016/02

See: The Stack Overflow Regular Expressions FAQ

Community
  • 1
  • 1
Cyrus
  • 84,225
  • 14
  • 89
  • 153