Bonjour,
Je fait appel à vos services pour l'écriture d'un script (shell) qui permettra de rechercher sur les "n" dernières lignes d'un fichier un caractère sur un champ précis.
Le fichier à analyser se compose de la manière suivante (fichier en question qui se compose ici de 26 lignes) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 Poli-3;2017-02-09 14:55:00.350;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 1;R;0 Poli-1;2017-02-09 14:55:00.359;IP_SERVEUR;TESTREJET;TEST_REJET_INT;URB2;KODI;Z;;OK_URL;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;TITI;data manquante format 1;V;0 Poli-10;2017-02-09 14:55:01.009;IP_SERVEUR;TESTREJET;TEST_VAL_INT;URB8;KODI;A;;OK_URL;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;;;;TITI;data manquante format 1;U;1 Poli-3;2017-02-09 14:56:00.350;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 1;R;0 Poli-1;2017-02-09 14:56:00.359;IP_SERVEUR;TESTREJET;TEST_REJET_INT;URB2;KODI;Z;;OK_URL;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;TITI;data manquante format 1;V;0 Poli-10;2017-02-09 14:56:01.009;IP_SERVEUR;TESTREJET;TEST_VAL_INT;URB8;KODI;A;;OK_URL;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;;;;TITI;data manquante format 1;U;1 Poli-2;2017-02-09 14:56:01.150;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;R;10 Poli-0;2017-02-09 14:56:02.150;IP_SERVEUR;TESTREJET;TEST_REJET_INT;URB5;KODI;D;;KO_TEMP;cache;AV5;proz-proe-ticket1;COSA;;;proa-noticket-proa;2016-06-12 14:33:02.389;;;;data OK format 8;;51 Poli-2;2017-02-09 14:56:02.150;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;R;10 Poli-4;2017-02-09 14:56:02.350;IP_SERVEUR;TESTREJET;;KODI;I;;KO_BIS;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;Z;10 Poli-3;2017-02-09 14:56:02.650;IP_SERVEUR;TESTREJET;TEST_REJET_ZOP;URB2;KODI;T;;KO_TER;cache;AV5;prob-proa-ticket1;Brique;;;;;;;data manquante format 8;E;10 Poli-3;2017-02-09 14:56:03.350;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 1;R;0 Poli-1;2017-02-09 14:56:03.359;IP_SERVEUR;TESTREJET;TEST_REJET_INT;URB2;KODI;Z;;OK_URL;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;TITI;data manquante format 1;V;0 Poli-10;2017-02-09 14:56:04.009;IP_SERVEUR;TESTREJET;TEST_VAL_INT;URB8;KODI;A;;OK_URL;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;;;;TITI;data manquante format 1;U;1 Poli-2;2017-02-09 14:56:04.050;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;R;10 Poli-0;2017-02-09 14:56:04.150;IP_SERVEUR;TESTREJET;TEST_REJET_INT;URB5;KODI;D;;KO_TEMP;cache;AV5;proz-proe-ticket1;COSA;;;proa-noticket-proa;2016-06-12 14:33:02.389;;;;data OK format 8;;51 Poli-2;2017-02-09 14:56:05.150;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;;10 Poli-4;2017-02-09 14:56:05.350;IP_SERVEUR;TESTREJET;;KODI;I;;KO_BIS;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;Z;10 Poli-3;2017-02-09 14:56:06.050;IP_SERVEUR;TESTREJET;TEST_REJET_ZOP;URB2;KODI;T;;KO_TER;cache;AV5;prob-proa-ticket1;Brique;;;;;;;data manquante format 8;E;10 Poli-0;2017-02-09 14:56:06.150;IP_SERVEUR;TESTREJET;TEST_REJET_INT;URB5;KODI;D;;KO_TEMP;cache;AV5;proz-proe-ticket1;COSA;;;proa-noticket-proa;2016-06-12 14:33:02.389;;;;data OK format 8;;51 Poli-2;2017-02-09 14:56:07.150;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;Z;10 Poli-4;2017-02-09 14:56:08.350;IP_SERVEUR;TESTREJET;;KODI;I;;KO_BIS;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;Z;10 Poli-3;2017-02-09 14:56:08.650;IP_SERVEUR;TESTREJET;TEST_REJET_ZOP;URB2;KODI;T;;KO_TER;cache;AV5;prob-proa-ticket1;Brique;;;;;;;data manquante format 8;E;10 Poli-1;2017-02-09 14:56:08.850;IP_SERVEUR;TESTREJET;TEST_REJET_EXT;URB1;KODI;A;;KO_ERREUR;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;Z;10 Poli-5;2017-02-09 14:56:09.350;IP_SERVEUR;TESTREJET;;KODI;I;;KO_BIS;cache;AV1;prob-proa-ticket1;Brique;;;prob-ticket1-proa;2016-06-12 14:33:02.389;;;;data manquante format 8;r;10 Poli-9;2017-02-09 14:56:09.650;IP_SERVEUR;TESTREJET;TEST_REJET_ZOP;URB2;KODI;T;;KO_TER;cache;AV5;prob-proa-ticket1;Brique;;;;;;;data manquante format 8;E;10
La où je pêche , c'est dans l'analyse de la ligne.
L'objectif est donc, d'analyser les "n" dernières lignes du fichier (n = paramètre donné en entrée de script - prenons en exemple 20) et de rechercher (=> comptabiliser) le caractère "R" (qui peut être en majuscule ou en minuscule) sur l'avant dernier champ de la ligne (le séparateur est le ";")
L'idée de départ était de faire un tail des "n" dernières lignes et d'utiliser soit le awk ou le sed pour analyser la ligne...
C'est là que ça se complique.
Résultat attendu :
--------------------
Nous comptabilisons en tout sur les 26 lignes du fichiers 7 fois le pattern "r" ou "R" sur l'avant dernier champs.
Nous souhaitons comptabiliser 5 fois le pattern "r" ou "R" en recherchant sur les 20 dernières ligne du fichier (=> paramètre donné en entrée de script).
Auriez-vous SVP une piste de départ pour analyser cette ligne ?
Par avance merci
Partager