Sed or Awk question, looking for parsing help
Hi, I have the following problem. I need a script that will find in a .csv file dates of format
Mon Mar 05 18:34:38 1982 and change them to this format inside the file: 03051982 Can this be done with sed? Does it have the ability to find a something using regular expressions and then modify it rather than replacing it? Or must this be done in awk? Any answers would be awesome. Thanks a lot. |
A possibility, though maybe not the best one:
Code:
sed '{s/[A-Z][a-z]\{2\} Jan \([0-9]\{2\}\) [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\} \([0-9]\{4\}\)/01\1\2/g} |
I think Perl is better solution. Use `map' datatype, for example %monts={"Jan" => 01, "Feb" => 02} or smth. like this.
Regular expression for whole date string: /\w* \w* \d{2} \d{2}:\d{2}:\d{2} \d{4}/. You can refer to month as $2 and substitute month number with $months[$2]. |
All times are GMT -5. The time now is 10:22 PM. |