0

Is there a command/script in linux or iwindows that will search through a list of TXT file and pull out any Date/time value found within those files and export it to a TXT which will contain the date/time and the filename it came from?

Thanks

K Ahmed
  • 21
  • 6
  • do you have any example? – Haifeng Zhang Mar 23 '16 at 19:50
  • 1
    Only if you specify format of a date you are loking for. If you hava format for example yyyymmdd you could use for loop and awk with regular expression. This can be done in linux. – dabal Mar 23 '16 at 19:51
  • @haifzhan this is an example of the date/time that exists within the TXT files: 19/06/2015 13:49:26 – K Ahmed Mar 23 '16 at 20:10
  • @dabal this is an example of the date/time that exists within the TXT files: 19/06/2015 13:49:26 – K Ahmed Mar 23 '16 at 20:11

1 Answers1

1

Try this with GNU grep for years from 1000 to 9999:

grep -Eo '[0-3][0-9]/[0-1][0-9]/[1-9][0-9]{3} [0-2][0-9]:[0-5][0-9]:[0-5][0-9]' file

See: The Stack Overflow Regular Expressions FAQ

Community
  • 1
  • 1
Cyrus
  • 69,405
  • 13
  • 65
  • 117
  • would you mind explaining what this part of the regex means : /[1-9][0-9]{3} i understood the other parts but this one is a bit confusing – K Ahmed Mar 24 '16 at 00:03
  • This match a slash followed by a digit (range 1 to 9) followed by three digits (range 0 to 9). Longer version: `/[1-9][0-9][0-9][0-9]` – Cyrus Mar 24 '16 at 00:32
  • See: [rick.measham.id.au](http://rick.measham.id.au/paste/explain.pl?regex=%2F[1-9][0-9]{3}) – Cyrus Mar 24 '16 at 01:18