Formatage de Fichier

Résolu/Fermé
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023 - 25 janv. 2017 à 14:58
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023 - 20 févr. 2017 à 10:52
Bonjour à tous

Bonne et heureuse année 2017

j'ai le fichier File1 ci-dessous et je veut obtenir le file FileX avec Awk.

File1

Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan1; 
Mvan2;
Mvan3;
Mvan6;
Mvan7;
Mvan8";Power issue;Power failure IHS solved the problem;



FileX
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan1;Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan2;Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan3;Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan6;Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan7;Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan8;Power issue;Power failure IHS solved the problem;
A voir également:

4 réponses

Utilisateur anonyme
25 janv. 2017 à 15:26
salut,

explique-nous la "mécanique" à mettre en oeuvre.
0
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023
25 janv. 2017 à 16:29
Salut ,

L'opération consiste à insérer à chaque fois les infos ci-dessous

Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;

et

Power issue;Power failure IHS solved the problem;

devant les pattern ci-dessous

"Mvan1;
Mvan2;
Mvan3;
Mvan6;
Mvan7;
Mvan8"

merci
0
zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
25 janv. 2017 à 17:06
Salut,

$ cat fich 
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan1;
Mvan2;
Mvan3;
Mvan6;
Mvan7;
Mvan8";Power issue;Power failure IHS solved the problem;


$ cat script.sed 
/^Critical/!{
s|^|Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;|
}
/Power issue/!{
s/$/Power issue;Power failure IHS solved the problem;/
}


$ sed -f script.sed fich 
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan1; Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS OM LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;Mvan2; Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS OM LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;Mvan3; Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS OM LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;Mvan6; Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS OM LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;Mvan7; Power issue;Power failure IHS solved the problem;
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS OM LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;Mvan8";Power issue;Power failure IHS solved the problem;

0
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023
26 janv. 2017 à 07:50
Bonjour Zipe31,

Merci pour ton retour , cependant ce n'est qu'un echantillon de fichier que j'ai posté.

mon fichier contient plus de mille ligne à traiter et avec différents libellés.

Ci-dessous un exemple.


Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan1 
Mvan2
Mvan3
Mvan6
Mvan7
Mvan8";Power issue;Power failure IHS solved the problem;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Critical;;Mvan-MRS-HIS_GD_CTR_487;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:53;IHS;"MVANMRSIHS1
MVANMRSIHS2
MVANMRSIHS3
MVANMRSIHS6
MVANMRSIHS7
MVANMRSIHS8";Power issue;Power failure IHS solved the problem;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Critical;IPD;Bberi-Château;2G;Douala;BTS O&M LINK FAILURE;05/12/2016 02:28;05/12/2016 09:26;6:58:01;IHS;"BBERICHATEAU1
BBERICHATEAU2
BBERICHATEAU3
BBERICHATEAU6
BBERICHATEAU7
BBERICHATEAU8 ";Power issue;Loss of the site configuration file of the System Module because of continuously restart of the SM due to power failure and low voltage supplied. The System Module was recommissioned;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Critical;Mak-Nodal;Denver;2G;Douala;BTS O&M Link Failure;05/12/2016 11:21;05/12/2016 12:05;0:43:53;IHS;"DENVER1
DENVER2
DENVER3
DENVER6
DENVER7
DENVER8";Power issue;Low voltage supplied (-175V). IHS was informed and they deployed a team who solved the problem;;;;;;;;;
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
26 janv. 2017 à 08:35
hello
y a-t-il toujours 8 champs DENVER1-8 Mvan1-8 ...?
0
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023 > dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024
Modifié par GHISLINO le 26/01/2017 à 09:02
Bonjour Dubcek,

Non le maxi est 9 comme l'exemple ci-dessous.

Critical;RNC-302;Foret-Bar-Mabanda-IHS;3G;Douala;WCDMA BASE STATION OUT OF USE;09/12/2016 18:19;10/12/2016 19:06;24:47:00;Ericsson;"Foret-Bar-Mabanda-IHS_u1  
Foret-Bar-Mabanda-IHS_u2
Foret-Bar-Mabanda-IHS_u3
Foret-Bar-Mabanda-IHS_u6
Foret-Bar-Mabanda-IHS_u7
Foret-Bar-Mabanda-IHS_u8
Foret-Bar-Mabanda-IHS_u11
Foret-Bar-Mabanda-IHS_u12
Foret-Bar-Mabanda-IHS_u13";Transmission issue;Transmission issue the ticket was sent and they've sent their team troubleshoot the incident;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Critical;RNC-302;Mabanda-MTN;3G;Douala;WCDMA BASE STATION OUT OF USE;09/12/2016 18:19;10/12/2016 19:06;24:47:00;Ericsson;"Mabanda-Mtn-Ihs_u1
Mabanda-Mtn-Ihs_u2
Mabanda-Mtn-Ihs_u3
Mabanda-Mtn-Ihs_u6
Mabanda-Mtn-Ihs_u7
Mabanda-Mtn-Ihs_u8
Mabanda-Mtn-Ihs_u11
Mabanda-Mtn-Ihs_u12
Mabanda-Mtn-Ihs_u13
";Transmission issue;Transmission issue the ticket was sent and they've sent their team troubleshoot the incident;
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
27 janv. 2017 à 07:47
si j'ai bien compris, il faut transformer
debut;c1
c2
c3
..
cn;fin

en
debut;c1;fin
debut;c2;fin
...
debut;cn;fin

?
essayer
$ awk -f f1.awk  <( awk 'BEGIN {FS=OFS=";"} NF>1 && !/Criti/ {$1=""; sub(FS "*$", ""); print}' fichier) fichier > log
$ head log
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;"Mvan1 ;;Power issue;Power failure IHS solved the problem
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;;Mvan2 ;;Power issue;Power failure IHS solved the problem
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;;Mvan3 ;;Power issue;Power failure IHS solved the problem
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;;Mvan6 ;;Power issue;Power failure IHS solved the problem
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;;Mvan7 ;;Power issue;Power failure IHS solved the problem
Critical;MCBSC_CBC;Mvan_CTR_108;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:44;IHS;;Mvan8";;Power issue;Power failure IHS solved the problem
Critical;;Mvan-MRS-HIS_GD_CTR_487;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:53;IHS;"MVANMRSIHS1 ;;Power issue;Power failure IHS solved the problem
Critical;;Mvan-MRS-HIS_GD_CTR_487;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:53;IHS;;MVANMRSIHS2 ;;Power issue;Power failure IHS solved the problem
Critical;;Mvan-MRS-HIS_GD_CTR_487;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:53;IHS;;MVANMRSIHS3 ;;Power issue;Power failure IHS solved the problem
Critical;;Mvan-MRS-HIS_GD_CTR_487;2G;Yaounde;BTS O&M LINK FAILURE;05/12/2016 10:47;05/12/2016 10:56;0:08:53;IHS;;MVANMRSIHS6 ;;Power issue;Power failure IHS solved the problem
$
$ head f1.awk
BEGIN {FS=OFS=";"}
ARGIND==1 {t[NR]=$0; next}
/Criti/ {n++; print $0, t[n]; $NF=""; a=$0; next}
NF>1 && !/Criti/ {$0=$1}
{print a, $0, t[n]}
0
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023
20 févr. 2017 à 10:52
Hello All,

Thanks a lot off for your support

BR
0