Recherche de chaines de caractères dans un fichier

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 28 juin 2002 à 00:36
PatDeLaYaute Messages postés 133 Date d'inscription dimanche 28 avril 2002 Statut Membre Dernière intervention 15 janvier 2009 - 28 juin 2002 à 14:40
Bonsoir (ou bonjour)

Je planche sur un code depuis 1 semaine...je me suis noyé.
Je cherche à capturer toutes les lignes où je trouve
" COMPLETED xxxx-FIN" (syntaxe exacte mais pas tjrs sur la même position sur la ligne).
Je ne veux pas de "OUTPUT COMPLETED...", ni autre ligne.
J'ai essayé avec instr mais je me suis égaré ds mes tests.
VicoLaChips a bien essayé de m'aider mais on s'est mal compris.
Je me retrouve avec des mssgs d'erreur hors séquence genre (i+15)
Attention, je bosse en VBScript, je n'ai pas VB.
Ci-dessous, exemple de mon fichier log:

[0 AN1G] FROM CRZ-GEP7 X6112 : FIN DU TRAITEMENT BOUR --> BOUR-FINI <--
[0 AN1G] OP33 UNKNOWN USER
[0 AN1G] 02.01 X6112.1 COMPLETED BOUR-FIN CRZ-GEP7 OB
[0 AN1G] 02.01 X6112 OUTPUT COMPLETED BOUR-FIN CRZ-GEP7 ON DEVICE W005
[0 AN1G] S: SEND ' BOUR TRAITEMENT TERMINE ' VICALPHA
[0 AN1G] S: Ejr Members=OUVRIQSB Lib=IMSB.JCL
[0 AN1G] TW06 R4483 REPORT COMPLETED
[0 AN1G] TW04 R4484 TERM=IIZZ USER=CRZ-GEP7 FROM X1490
[0 AN1G] 02.03 X6112.45 COMPLETED PNEU-FIN CRZ-TEST OA
[0 AN1G] FROM CRZ-GEP7 X6150 : == (SVEDMENA) == .......... FIN .......... ==
[0 AN1G] 02.04 X6150.1 COMPLETED SVEDMENA CRZ-GEP7 OA
[0 AN1G] TW08 R4484 UNABLE TO START: UNKNOWN REPORT
[0 AN1G] TW09 R4484 REPORT CANCELLED BY SYSTEM
[0 AN1G] 02.01 X6112.256 COMPLETED ALES-FIN CRZ-TEST OA
[0 AN1G] TW04 R4485 TERM=IIZZ USER=CRZ-GEP7 FROM X1490
[0 AN1G] 02.04 X6150 OUTPUT COMPLETED SVEDMENA CRZ-GEP7 ON

Dans cet exemple, il me faut seulement les lignes:
[0 AN1G] 02.01 X6112.1 COMPLETED BOUR-FIN CRZ-GEP7 OB
[0 AN1G] 02.03 X6112.45 COMPLETED PNEU-FIN CRZ-TEST OP
[0 AN1G] 02.01 X6112.256 COMPLETED ALES-FIN CRZ-TEST OA
Après, pour la présentation de mon mssg console, je selectionnerais
02.01 => hh.mn / xYYYY.??? => mon numéro chrono de batch / xxxx-FIN => le nom de mon job

Ex de mon code (qui est faux !!!):
Dim mm, jjmmaa
mm = month(now)
IF Len(mm) = 1 Then
mm = "0" & mm
End If
jjmmaa = Left(Date,2) & "_" & mm & "_" & Right(Date,2)

Dim fso, Path, FicLog, Fichier
Dim objTextStream, strListe
Path = "c:\Scripts-VBS"
Fichier = "log-crouzet.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
' fso.CopyFile "c:\Partage Jean-Marc" & jjmmaa & ".wgo", "c:\Scripts-VBS\log-crouzet_" & jjmmaa & ".txt"
Set objTextStream = fso.OpenTextFile(Path & Fichier, 1)

MsgBox ShowFolderList(Path),vbmessage,"Vérification de la fin des exploitations du client CROUZET" & " Log: " & Fichier

Function ShowFolderList(strPath)
Dim strtmp, i, hh, mn, ron
Do while not objTextStream.AtEndOfStream
strtmp = split(objtextstream.readline," ")
For i = 0 to Ubound(strTmp)
IF instr(trim(strtmp(i)),"COMPLETED") Then
msgBox "Position: " & strtmp(i) & " i=> position " & i
hh = Left(strtmp(i-1),2)
mn = Right(strtmp(i-1),2)
ron = Right(strtmp(i-1),4)

strListe = strListe & vbcrlf & vbcrlf & "Le batch " & strtmp(i+1) & " (x)" & ron & " s'est terminé à " & hh & "h" & mn
End If
Next
loop
ShowFolderList = strListe
End Function
Set fso = Nothing

L'anomalie vient de "REPORT COMPLETED" que je n'aurais pas du selectionner
La commande => msgBox "Position: " & strtmp(i) & " i=> position " & i
me permets de visualiser les positions i (en test)

3 réponses

PatDeLaYaute Messages postés 133 Date d'inscription dimanche 28 avril 2002 Statut Membre Dernière intervention 15 janvier 2009 3
28 juin 2002 à 09:26
Salut,
pour repérer les lignes qui t'interressent essaie avec ca :

Dim Pos1%, Pos2%
Pos1%= instr(trim(strtmp(i)),"COMPLETED")
Pos2%= instr(trim(strtmp(i)),"FIN")

IF Pos1%<>0 and Pos1% BOUR-FINI <--
[0 AN1G] OP33 UNKNOWN USER
[0 AN1G] 02.01 X6112.1 COMPLETED BOUR-FIN CRZ-GEP7 OB
[0 AN1G] 02.01 X6112 OUTPUT COMPLETED BOUR-FIN CRZ-GEP7 ON DEVICE W005
[0 AN1G] S: SEND ' BOUR TRAITEMENT TERMINE ' VICALPHA
[0 AN1G] S: Ejr Members=OUVRIQSB Lib=IMSB.JCL
[0 AN1G] TW06 R4483 REPORT COMPLETED
[0 AN1G] TW04 R4484 TERM=IIZZ USER=CRZ-GEP7 FROM X1490
[0 AN1G] 02.03 X6112.45 COMPLETED PNEU-FIN CRZ-TEST OA
[0 AN1G] FROM CRZ-GEP7 X6150 : == (SVEDMENA) == .......... FIN .......... ==
[0 AN1G] 02.04 X6150.1 COMPLETED SVEDMENA CRZ-GEP7 OA
[0 AN1G] TW08 R4484 UNABLE TO START: UNKNOWN REPORT
[0 AN1G] TW09 R4484 REPORT CANCELLED BY SYSTEM
[0 AN1G] 02.01 X6112.256 COMPLETED ALES-FIN CRZ-TEST OA
[0 AN1G] TW04 R4485 TERM=IIZZ USER=CRZ-GEP7 FROM X1490
[0 AN1G] 02.04 X6150 OUTPUT COMPLETED SVEDMENA CRZ-GEP7 ON

Dans cet exemple, il me faut seulement les lignes:
[0 AN1G] 02.01 X6112.1 COMPLETED BOUR-FIN CRZ-GEP7 OB
[0 AN1G] 02.03 X6112.45 COMPLETED PNEU-FIN CRZ-TEST OP
[0 AN1G] 02.01 X6112.256 COMPLETED ALES-FIN CRZ-TEST OA
Après, pour la présentation de mon mssg console, je selectionnerais
02.01 => hh.mn / xYYYY.??? => mon numéro chrono de batch / xxxx-FIN => le nom de mon job

Ex de mon code (qui est faux !!!):
Dim mm, jjmmaa
mm = month(now)
IF Len(mm) = 1 Then
mm = "0" & mm
End If
jjmmaa = Left(Date,2) & "_" & mm & "_" & Right(Date,2)

Dim fso, Path, FicLog, Fichier
Dim objTextStream, strListe
Path = "c:\Scripts-VBS"
Fichier = "log-crouzet.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
' fso.CopyFile "c:\Partage Jean-Marc" & jjmmaa & ".wgo", "c:\Scripts-VBS\log-crouzet_" & jjmmaa & ".txt"
Set objTextStream = fso.OpenTextFile(Path & Fichier, 1)

MsgBox ShowFolderList(Path),vbmessage,"Vérification de la fin des exploitations du client CROUZET" & " Log: " & Fichier

Function ShowFolderList(strPath)
Dim strtmp, i, hh, mn, ron
Do while not objTextStream.AtEndOfStream
strtmp = split(objtextstream.readline," ")
For i = 0 to Ubound(strTmp)
IF instr(trim(strtmp(i)),"COMPLETED") Then
msgBox "Position: " & strtmp(i) & " i=> position " & i
hh = Left(strtmp(i-1),2)
mn = Right(strtmp(i-1),2)
ron = Right(strtmp(i-1),4)

strListe = strListe & vbcrlf & vbcrlf & "Le batch " & strtmp(i+1) & " (x)" & ron & " s'est terminé à " & hh & "h" & mn
End If
Next
loop
ShowFolderList = strListe
End Function
Set fso = Nothing

L'anomalie vient de "REPORT COMPLETED" que je n'aurais pas du selectionner
La commande => msgBox "Position: " & strtmp(i) & " i=> position " & i
me permets de visualiser les positions i (en test)
0
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
28 juin 2002 à 10:07
Bonjour,

Erreur caractère incorrect ligne:xx caract:9
xx => correspond à: Dim Pos1%, Pos2%
Apparemment, VBS n'apprécie pas le %

Dim Pos1%, Pos2%, strtmp, i, hh, mn, ron
Do while not objTextStream.AtEndOfStream
strtmp = split(objtextstream.readline," ")
IF Pos1%<>0 and Pos1% position " & i
0
PatDeLaYaute Messages postés 133 Date d'inscription dimanche 28 avril 2002 Statut Membre Dernière intervention 15 janvier 2009 3
28 juin 2002 à 14:40
Je connais pas le VBS, mais a ce que je sais c'est presque comme VB, enfin.
Essaie de faire sans la déclaration de type %
Le but est seulement de savoir si dans ta ligne il y a "COMPLETED" et "FIN", et que "FIN" ce trouve après "COMPLETED".

@+
0
Rejoignez-nous