2016-05-17 5 views
0

Ich habe Ausgabe von mehreren verschiedenen Protokolldatei.Ich verwende unter Befehl aus der Protokolldatei herausfiltern.Ich brauche den Ausgabefilter durch Datum und Uhrzeit und die gesamte Ausgabe sollte in der Sortierreihenfolge nach Datum und Uhrzeit angezeigt werden. Und das gesamte Ergebnis sollte in einer Datei zusammengefasst werden. Ich suche den Profiling-Benutzer mit @ABC und @DEF und lösche auch die doppelten Einträge. Wie formatiert Ausgabe in Datum und Uhrzeit von Protokolldateien und löschen doppelten Eintrag von der Ausgabe

cat log_file1.log | grep 'Profiling user :' | awk '{print $1,$21}' | cut -c2- | grep '@ABC' 

Ausgabe von log_file1.log

2016-05-16T10:50:09.170+00:00] [email protected] 
    2016-05-16T10:50:09.170+00:00] [email protected] 
    2016-05-16T10:56:43.944+00:00] [email protected] 
    2016-05-16T10:56:43.944+00:00] [email protected] 
    2016-05-16T11:00:55.961+00:00] [email protected] 
    2016-05-16T11:00:55.961+00:00] [email protected] 
    2016-05-16T11:12:23.326+00:00] [email protected] 
    2016-05-16T11:12:23.326+00:00] [email protected] 
    2016-05-16T11:26:35.311+00:00] [email protected] 
    2016-05-16T11:26:35.311+00:00] [email protected] 
    2016-05-16T12:08:33.719+00:00] [email protected] 
    2016-05-16T12:08:33.719+00:00] [email protected] 
    2016-05-16T12:58:40.453+00:00] [email protected] 
    2016-05-16T12:58:40.453+00:00] [email protected] 
    2016-05-16T13:44:45.657+00:00] [email protected] 
    2016-05-16T13:44:45.657+00:00] [email protected] 
    2016-05-16T14:42:35.818+00:00] [email protected] 
    2016-05-16T14:42:35.818+00:00] [email protected] 
    2016-05-16T14:46:07.353+00:00] [email protected] 

Ausgabe von log_file2.log

2016-05-12T08:16:49.438+00:00] [email protected] 
2016-05-12T08:16:49.438+00:00] [email protected] 
2016-05-12T08:32:52.239+00:00] [email protected] 
2016-05-12T08:32:52.239+00:00] [email protected] 
2016-05-12T08:52:19.074+00:00] [email protected] 
2016-05-12T08:52:19.074+00:00] [email protected] 
2016-05-12T09:39:48.475+00:00] [email protected] 
2016-05-12T09:39:48.475+00:00] [email protected] 
2016-05-12T09:58:42.659+00:00] [email protected] 
2016-05-12T09:58:42.659+00:00] [email protected] 
2016-05-12T11:45:58.756+00:00] [email protected] 
2016-05-12T11:45:58.756+00:00] [email protected] 
2016-05-12T12:36:02.116+00:00] SHAN[email protected] 
2016-05-12T12:36:02.116+00:00] [email protected] 
2016-05-12T13:03:52.589+00:00] [email protected] 
2016-05-12T13:03:52.589+00:00] [email protected] 

Katze logfile_3.log | grep 'Benutzer Profiling:' | awk '{print $ 1, $ 21}' | schneiden -c2- | grep '@DEF'

2016-05-12T13:50:40.132+00:00] [email protected] 
2016-05-12T13:50:40.132+00:00] [email protected] 
2016-05-12T14:06:32.173+00:00] [email protected] 
2016-05-12T14:06:32.173+00:00] [email protected] 

I Ausgang wie unten benötigen: -

Date  Time    User 
    2016-05-16 8:16:49  [email protected] 
    2016-05-16 8:16:49  [email protected] 
    2016-05-16 8:32:52  [email protected] 
    2016-05-16 8:32:52  [email protected] 
    2016-05-16 8:52:19  [email protected] 
    2016-05-16 8:52:19  [email protected] 
    2016-05-16 9:39:48  [email protected] 
    2016-05-16 9:39:48  [email protected] 
    2016-05-16 9:58:42  [email protected] 
    2016-05-16 9:58:42  [email protected] 
    2016-05-16 11:45:58 [email protected] 
    2016-05-16 11:45:58 [email protected] 
    2016-05-16 12:36:02 [email protected] 
    2016-05-16 12:36:02 [email protected] 
    2016-05-16 13:03:52 [email protected] 
    2016-05-16 13:03:52 [email protected] 
    2016-05-16 13:50:40 [email protected] 
    2016-05-16 13:50:40 [email protected] 
    2016-05-16 14:06:32 [email protected] 
    2016-05-16 14:06:32 [email protected] 
    2016-05-16 10:50:09 [email protected] 
    2016-05-16 10:56:43 [email protected] 
    2016-05-16 10:56:43 [email protected] 
    2016-05-16 10:50:09 [email protected] 
    2016-05-16 11:00:55 [email protected] 
    2016-05-16 11:00:55 [email protected] 
    2016-05-16 11:12:23 [email protected] 
+0

nicht verwenden 'grep' und' cut' in der gleichen Pipeline wie 'awk'. 'awk' kann alles 'grep' und' cut' können. –

+0

Tipp: Schlagen Sie 'split' im' awk'-Handbuch nach. –

+0

@Michael Vehrs - wie man awk Befehl verwendet, um alles stuff.at zu machen lleast, wie man filtert heraus in '5/12/2016 8:16:49 [email protected]' – Ajinkya

Antwort

1

Dies ist eine Teillösung, ein sane Datumsformat:

/Profiling user :/ && ($21 ~ "@ABC.com" || $21 ~ "@DEF.com") { 
    split($1, time, "[^0-9]"); 
    print time[4] "/" time[3] "/" time[2] "\t" $21; 
} 
+0

Ich benutze diesen Befehl habe das Ergebnis unten, aber ich könnte die Zeit bekommen 'cat b.log | awk '/ Profiling-Benutzer:/&& ($ 21 ~ "@ABC" || $ 21 ~ "@DEF") {split ($ 1, time, "[^ 0-9]"); Druckzeit [4] "-" Zeit [3] "-" Zeit [2] "\ t" $ 21;} "" 12-05-2016 AB.RAZA @ ABC.COM' '12-05-2016 BEEN .RAZA @ ABC.COM' – Ajinkya

+0

danke viel ich finde den deinen weg .. 'cat b.log | awk '/ Profiling-Benutzer:/&& ($ 21 ~ "@DEF" || $ 21 ~ "@ABC") {split ($ 1, time, "[^ 0-9]"); Druckzeit [4] "-" Zeit [3] "-" Zeit [2] "\ t" Zeit [5] ":" Zeit [6] ":" Zeit [7] "\ t" $ 21;} " – Ajinkya

+0

@Ajinkya Verwenden Sie nicht 'Katze' so. 'awk' nimmt Dateinamen Argumente. –