0

I have a csv file like this, that I'm editing in bash:

SI ID;SI Status;Priorität;Kategorie betroffenes Produkt;Komponente(n);Betroffene Betriebsumgebung;Sicherheitsrelevanz;Datenschutzrelevanz;TI Notfall;Zeit Erfassung;SI Melder;SI Bearbeiter;SI Beschreibung;Aktualisiert;SI Zieltermin;SI Lösung;Meldungstyp TTI-46;Gelöst;1;PDT02 TSP-X.509QES ;PDT02 TSP-X.509QES ;TU;;;;13.Sep.17 11:56;CGMAG;CGMAG;Test;13.Sep.17 11:57;;Gelöst;SI TTI-44;Gelöst;2;PDT03 TSP-X.509nonQES ;PDT03 TSP-X.509nonQES ;;;;;12.Sep.17 15:51;dennis.rittmeier;dennis.rittmeier;OPBI00039942 - Https-Verbindungen über SIS - zu langsam oder gar nicht aufgebaut;15.Sep.17 7:53;;Gelöst;SI

What I want is to convert all date/times "bold" from this Format 15.Sep.17 15:53 to 2017-09-15T15:53:00+02

Please can anybody help me?

Cyrus
  • 84,225
  • 14
  • 89
  • 153

1 Answers1

0
$ d="12.Sep.17 15:51"
$ date -d "$(tr "." " " <<<"$d")" "+%FT%T%z"
2017-09-12T15:51:00-0400

I'm in the Canada Eastern time zone, hence the -0400

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • Hi, thank you for the help! `➤ grep -o ..\....\...\ ..:.. test.csv | while read line; do date -d "$(tr "." " " <<<"$line")" "+%FT%T%z"; echo "$line"; done date: invalid date '13 Sep 17 11:56' 13.Sep.17 11:56 date: invalid date '13 Sep 17 11:57' 13.Sep.17 11:57 date: invalid date '12 Sep 17 15:51' 12.Sep.17 15:51 ` Why it call invalid date time? When it write `➤ tr "." "." ` the script interprete the date right but it's always say wrong date. Need help... Sorry im bad at bash. Thank you! – Stephan Mallmann Sep 18 '17 at 06:16
  • ok, on a different bash it works fine! Thank you – Stephan Mallmann Sep 18 '17 at 06:52