PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Datum in Logdatei ändern von MM/DD/YYYY nach YYYY-MM-DD ?



Linus
25-01-2016, 21:29
Ich habe Logdateien von einer USV, einmal Daten:



Network Management Card AOS v6.2.1
Smart-UPS & Matrix-UPS APP v6.2.1

Date Time Name Contact Location System IP
01/21/2016 20:55:40 apc8A6DA2 Unknown Unknown 10.11.12.1

Smart-UPS 750
Date Time Vmin Vmax Vout Iout %Wout %out FrqOut %Cap Vbat Tups
01/21/2016 20:50:44 227.50 230.39 228.89 0.50 16.19 14.89 50.00 100.00 27.00 32.80
01/21/2016 20:40:44 227.50 230.39 228.89 0.53 16.19 16.19 49.97 100.00 27.00 32.80
01/21/2016 20:30:44 228.89 230.39 230.39 0.50 16.19 15.59 49.97 100.00 27.00 32.80
01/21/2016 20:20:44 228.89 230.39 230.39 0.28 9.69 9.09 50.00 100.00 27.00 32.39
01/21/2016 20:10:44 228.89 230.39 228.89 0.28 9.69 9.09 49.97 100.00 27.00 32.39
01/21/2016 20:00:44 228.89 230.39 228.89 0.28 9.69 9.09 49.94 100.00 27.00 32.80
01/21/2016 19:50:44 228.89 230.39 230.39 0.28 9.09 9.09 49.97 100.00 27.00 32.80
01/21/2016 19:40:44 228.89 230.39 230.39 0.28 9.09 9.09 50.00 100.00 27.00 32.39
01/21/2016 19:30:44 228.89 230.39 230.39 0.28 9.69 9.09 49.98 100.00 27.00 32.39
...



und Events:




Network Management Card AOS v6.2.1
Smart-UPS & Matrix-UPS APP v6.2.1

Date Time Name Contact Location System IP
01/21/2016 20:55:26 apc8A6DA2 Unknown Unknown 10.11.12.1

Date Time User Event Code
12/10/2015 19:18:54 System Network Interface coldstarted. 0x0001
12/10/2015 17:22:18 Device UPS: The output power is turned off. 0x0114
12/10/2015 17:22:18 Device UPS: The graceful shutdown period has ended. 0x014F
12/10/2015 17:22:18 Device UPS: No longer on battery power. 0x010A
12/10/2015 17:22:18 Device UPS: The power for the main outlet group, UPS Outlets, is now turned off. 0x0135
12/10/2015 17:21:55 Device UPS: Main outlet group, UPS Outlets, has been commanded to reboot with off delay. 0x0174
12/10/2015 17:16:37 Device UPS: On battery power in response to distorted input. 0x0109
11/03/2015 14:55:58 Device UPS: No longer on battery power. 0x010A
11/03/2015 14:55:24 Device UPS: On battery power in response to distorted input. 0x0109
11/03/2015 14:23:18 Device UPS: The output power is now turned on. 0x0113
11/03/2015 14:23:17 Device UPS: The power for the main outlet group, UPS Outlets, is now turned on. 0x0134
11/03/2015 14:18:19 Device UPS: The output power is turned off. 0x0114
...


Über cat, sort, uniq usw. bekomme ich es hin diese stündlich gesammelten Dateien zusammenzuführen zu einer, die alle Daten ohne mehrfache Zeilen enthält, aber wegen dem Murks-Datum am Zeilenanfang ist das Ergebnis a) schwer lesbar, da das Datum nicht streng monoton aufgebaut ist und b) ist ein Folgefehler das die sortierten Daten nicht in zeitlicher Reihenfolge sind.
Daher soll das Datum vom Format MM/DD/YYYY geändert werden nach YYYY-MM-DD, aber wie bekommt man das mit einem Skript hin? :confused:

Und wie bekommt man die Zeilen weggefiltert, die nicht mit einem Datum im Format MM/DD/YYYY beginnen? :confused:

zst
26-01-2016, 16:04
Hallo,
das WEGFILTERN kann so gehen:


grep "^[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9] " GESAMTDATEI >NEUEDATEI

Und damit kein "Folgefehler" bei der Datum-Sortierung entsteht, musst du dein "sort" mit "-k" benutzen.
Vielleicht genügt es dir ja dann, andernsfalls musst du dann doch noch das Datum in dein Format konvertieren.
Gruß zst

Linus
26-01-2016, 18:41
Danke für den Tip.
Ohne Datum-Umwandlung hilft mir das nur wenig weiter, so das ich das nur zur Vorfilterung nutze, die Hauptarbeit aber mit einem C-Programm mache.
Damit mache ich auch eine erste Auswertung für jede Spalte mit Min, Max, Avg, Stddev (Standardabweichung). Schließlich will ich nicht nur zu einem bestimmten Zeitpunkt wissen wie die Werte da waren sondern auch eine grobe Übersicht haben was sonst so los war.

Linus
27-01-2016, 23:21
Nachtrag: Das Umwandeln geht auch mit dd, weil feste Feldbreiten verwendet werden, mit sowas wie



while read line
do # write day, month and year, append
cat $line | dd of=mm.txt bs=1 count=2
cat $line | dd of=dd.txt bs=1 count=2 skip=3
cat $line | dd of=yyyy.txt bs=1 count=4 skip=6
echo "-" >> yyyy.txt
cat mm.txt >> yyyy.txt
echo "-" >> yyyy.txt
cat dd.txt >> yyyy.txt
cat $line | dd append of=yyyy.txt bs=1 skip=10
done < data.txt