简体   繁体   中英

How can I detect a date from the content of a file using %F bash shell

I have some files that have date inside and I want to check if the content of the file is more current. I can check for comparison of dates but I cannot grep date from the file. for example in file1 i have:

my name is Adelaide in Lagos 9:29AM (Author)}||2015-03-13 13:12:59.239308|2012-07-09 10:00:00|reading|3110311|off the internet |3012364|3012364|3012364|63613191| SectionStart 

file2 has:

63615595| Summary|Final|New Roman; Name if here for  earsProvider: ||2015-03-13 13:12:59.239308| Summary 2012-07-09 09:00:00|2210299|3110311|2824032|O6550610|63615595|

Since they are not in conformity of table and a file can have more than one date format in it, I only want to retrieve the dates with yyyy-mm-dd hh:mm:ss format.

尝试使用GNU grep来获得时间戳记:

grep -oP '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-2][0-9]:[0-5][0-9]:[0-5][0-9](?=\|)' file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM