I have a log line like this:
Tue Dec 2 10:03:46 2014 1 10.0.0.1 0 /home/test4/TEST_LOGIN_201312021003.201412021003.23872.sqlLdr b _ i r test4 ftp 0 * c
And I can print date value of this line like this.
echo $log | awk '{print $9}' | grep -oP '(?<!\d)201\d{9}' | head -n 1
I have another log line like this, how can I print date value?
Tue Dec 9 10:48:13 2014 1 10.0.0.1 80 /home/DATA1/2014/12/11/16/20/blablabla_data-2014_12_11_16_20.txt b _ i r spy ftp 0 * c
I tried my awk/grep solution, but it prints 201
and 9
number after 201
when see 201
.
Sub folders and data name is the same:
2014/12/11/16/20 --> 11 Dec 2014 16:20 <-- blablabla_data-2014_12_11_16_20.txt
note: /home/DATA1
is not static. year/month/day/hour/minute
is static.
sed can also work too, if you are acquainted with it
output
To remove "/", the same above command piped to
tr -d '/'
Full command line
Output
As the format in the path is
/.../YYYY/MM/DD/HH/MM/filename
, you can use201D/DD/DD/DD/DD
in thegrep
expression to match the date block:And eventually remove the slashes with
tr
: