houba91
Messages postés11Date d'inscriptionvendredi 21 mars 2014StatutMembreDernière intervention21 mai 2014
-
Modifié par cs_Julien39 le 28/04/2014 à 09:39
Twinuts
Messages postés5375Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention14 juin 2023
-
2 avril 2014 à 09:20
Bonjour,
j'ai besoin d'aide. En fait j'ai un fichier log sous format txt voici un morceau
1394950584.861 438 10.0.149.23 TCP_MISS/200 934 GET http://dzayfdqe.trwvksnpc.au/lsetyumxs.html - DIRECT/69.114.1.230 text/html
1394950629.431 580 10.0.149.23 TCP_MISS/200 922 GET http://oacsyus.jxjsaz.tz/znvr.html - DIRECT/79.179.220.28 text/html
1394950629.862 460 10.0.149.23 TCP_MISS/200 1860 GET http://jfgmbt.pfkaa.cat/ogwblsah.html - DIRECT/219.135.237.57 text/html
1394950632.629 849 10.0.149.23 TCP_MISS/200 607 GET http://qpslzh.ngqde.construction/yhhbzllx.html - DIRECT/202.34.56.241 text/html
1394950633.244 916 10.0.149.23 TCP_MISS/200 1651 GET http://psficabij.hklrmkfm.mv/vqjfld.html - DIRECT/154.252.249.81 text/html
1394950633.687 906 10.0.149.23 TCP_MISS/200 182 GET http://weiovu.vlscqtzwh.sz/mltwecfgg.html - DIRECT/176.245.255.69 text/html
1394950636.311 678 10.0.149.23 TCP_MISS/200 1839 GET http://iwcrr.nfveakyas.mp/ayusm.html - DIRECT/152.85.2.88 text/html
je souhaite découper chaque ligne en des champs par exemple
pour la ligne 1 je voudrais avoir le champs ClientIP qui 10.0.149.23 et les champs serveur et la page demandé
J'ai pensé à écrire une expression régulière pour chaque ligne voila l'expression
([0-9]{10})(.[0-9]{3})( +)([0-9]+)( +)([0-9]\\d{0,2}\\.){3}[0-9]\\d{0,2}( +)([A-Z]+)(_[A-Z]+)(/[0-9]+)( +)([0-9]+)( +)(GET)( +)(http://)([a-z]+)(.[a-z]+)(.[a-z]+)(/[a-z]+)(.html)( +)(-)( +)([A-Z]+)(/([0-9]\\d{0,2}\\.){3}[0-9]\\d{0,2})( +)([a-z]+)(/html)
svp aidez moi comment faire
Twinuts
Messages postés5375Date d'inscriptiondimanche 4 mai 2003StatutModérateurDernière intervention14 juin 2023111 2 avril 2014 à 09:20
Salut,
Si tu veux simplement segmenter tes champs tu peux faire un split(" ") (ou utiliser un StringTokenizer) sur ta ligne et du coup tous les champs seront dans une dimension de ton split.
Cela dit il est possible d'appliquer ta regex (en java l'espace est représenté par \s soit \\s dans une string) mais pas d'un bloc. Il te faut décomposer la regex.
// il y a surement beaucoup plus beau/simple que ma solution import java.io.File; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern;
final Scanner sc = new Scanner(new File("thefile.txt")); String line; int i; while (sc.hasNextLine()) { line = sc.nextLine(); i = 0; Matcher match = pp[i].matcher(line); while (match.find() && i < pp.length - 1) { System.out.println("==> " + match.group()); match = match.usePattern(pp[++i]); } } sc.close(); } }