Exraire les donnes d'un fichier - Page 2

Résolu
Précédent
  • 1
  • 2
  1. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    on peut pas intégrer le paramètre nom fichier (tg) dans la boucle au lieu de le rentrer et d'orienter chaque fois la ligne dans un fichier finale
    merci d'avance
    0
  2. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    je viens de tester ca
    open(FP,'<','tg');

    while (<FP>) {
    ($c1,$c2,$c3,$c4)=split(/\+/); $c4 =~s/(^[\d]+\.[\d]+).*$/\1/ ; if($c4 > 10){print $_}
    }

    il marche mais je cherche a orienter les lignes vers d'autre fichier

    et merci d'avance
    0
  3. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
     
    $ cat p1
    open (STDIN, "< tg");
    while (<>) {
    	($c1,$c2,$c3,$c4)=split(/\+/); $c4 =~s/(^[\d]+\.[\d]+).*$/\1/ ; if($c4 > 10){print $_}
    }
    0
  4. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    reste a rediriger l'affichage vers un autre fichier et c'est fini
    merci d'avance
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      #25
      0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    mais s marche pas quand j'ajoute ca:>

    ($c1,$c2,$c3,$c4)=split(/\+/); $c4 =~s/(^[\d]+\.[\d]+).*$/\1/ ; if($c4 >$a ){print $_}>test;
    merci d'avance
    0
  7. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
     
    soit
    perl script > log
    soit
    open (LOG, ">log");
    open (STDIN, "< tg");
    while (<>) {
    	($c1,$c2,$c3,$c4)=split(/\+/); $c4 =~s/(^[\d]+\.[\d]+).*$/\1/ ; if($c4 > 10){print LOG $_}
    }
    0
  8. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    je te remercie
    sans toi ca aurait été difficile
    merci
    0
  9. mamiemando Messages postés 33174 Date d'inscription   Statut Modérateur Dernière intervention   7 944
     
    Au passage si tu peux ouvrir un nouveau sujet pour chaque nouvelle question... ce serait cool :-)
    0
  10. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    Bonjour;

    serait il d'avoir des explications sur cette ligne:
    ($c1,$c2,$c3,$c4)=split(/\+/); $c4 =~s/(^[\d]+\.[\d]+).*$/\1/ ;

    par ce que j'aurai besoin de faire d'autre extraction
    en fait je voulais extraire les adresse mac dont leur state et free en passant par script Perl
    voila un exemple de fichier

    merci d'avance de votre aide

    lease 192.168.100.10 {
    starts 3 2012/03/28 08:01:45;
    ends 3 2012/03/28 08:11:45;
    tstp 3 2012/03/28 08:11:45;
    cltt 3 2012/03/28 08:01:45;
    binding state free;
    hardware ethernet 00:20:d2:25:54:23;
    }
    lease 192.168.100.2 {
    starts 1 2012/04/02 09:54:36;
    ends 1 2012/04/02 09:55:48;
    tstp 1 2012/04/02 09:55:48;
    cltt 1 2012/04/02 09:54:36;
    binding state free;
    hardware ethernet 00:14:22:c3:38:53;
    uid "\001\000\024\"\3038S";
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:35:26;
    ends 3 2012/04/04 14:36:38;
    cltt 3 2012/04/04 14:35:26;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:02;
    ends 3 2012/04/04 14:37:14;
    cltt 3 2012/04/04 14:36:02;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:38;
    ends 3 2012/04/04 14:37:50;
    cltt 3 2012/04/04 14:36:38;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    0
    1. dubcek Messages postés 18627 Date d'inscription   Statut Contributeur Dernière intervention   5 660
       
      serait il d'avoir des explications sur cette ligne:
      ($c1,$c2,$c3,$c4)=split(/\+/)	on stocke les 4 premiers champs séparés par + dans des variables c1, c2 ...
      $c4 =~s/(^[\d]+\.[\d]+).*$/\1/		on modifie c4 en ne gardant que : [chiffres] point [chifres], donc de 10.11.12, on ne garde que 10.11
      0
  11. mamiemando Messages postés 33174 Date d'inscription   Statut Modérateur Dernière intervention   7 944
     
    L'idéal ce serait que tu regardes un cours sur les expressions régulières ou sur sed :
    https://fr.wikipedia.org/wiki/Expression_rationnelle
    https://fr.wikipedia.org/wiki/Stream_Editor

    - split : sépare une chaîne en un tableau ou chaque cellule est délimitée par un caractère (ici +). Le + est précédé d'un \ car c'est un meta-caractère des expressions régulières

    - (^[\d]+\.[\d]+).*$
    ^: commence par
    \d : un entier
    [\d]+: un entier répété entre 1 et une infinité de fois
    \. : le caractère "." (car "." est aussi un meta-caractère des expressions régulières)
    [\d]+\.[\d]+ : décrit dont une valeur flottante (dans ton cas ce sont en fait les deux premiers nombres d'une ipv4)
    ([\d]+\.[\d]+) : les parenthèses ici permettent de dire qu'on va extraire dans une variable temporaire. Cette variable sera désignée par \1. Dans l'absolu on peut extraire plusieurs morceaux qui seront respectivement désignés \1, \2 etc...
    - . : n'importe quel caractère
    - .* : une répétition entre 0 et une infinité de fois
    - $ : fini par (on voit donc que .*$ est probablement superflu)

    s/motif/substition : remplace la première occurrence de motif par substitution : ici la substitition correspond à la variable \1 (donc le flottant que tu as extrait). Ceci revient donc à écrire le morceau que tu as extrait (par exemple 11.22), mais si on avait mis >\1< par exemple, ça aurait consisté à la réécrire encadrée des caractères >...< (ici >11.22<).

    Bonne chance
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Salut mamie,

      Sans compter que la solution lui a été donnée là par dubcek avec "awk", et juste au-dessus pour "sed" ;-\

      Et je ne parle même pas de ça ;-(
      0
    2. mamiemando Messages postés 33174 Date d'inscription   Statut Modérateur Dernière intervention   7 944
       
      Oui je suis d'accord avec toi, othmane19 pourrait s'investir un petit peu plus...
      0
  12. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    merci pour vos réponse
    justement j'étais entrain de tester avec les solutions proposé mais je vois que cette commande ne marche pas avec le fichier que j'ai.
    je pense qu'il faut adapter la commande sed mais j'ai du mal avec cette commande
    merci d'avance

    sed -n '/^binding state free/{:z;n;/^hardware/! bz;p}' f

    voila le fichier l'exemple du fichier :
    lease 192.168.100.10 {
    starts 3 2012/03/28 08:01:45;
    ends 3 2012/03/28 08:11:45;
    tstp 3 2012/03/28 08:11:45;
    cltt 3 2012/03/28 08:01:45;
    binding state free;
    hardware ethernet 00:20:d2:25:54:23;
    }
    lease 192.168.100.2 {
    starts 1 2012/04/02 09:54:36;
    ends 1 2012/04/02 09:55:48;
    tstp 1 2012/04/02 09:55:48;
    cltt 1 2012/04/02 09:54:36;
    binding state free;
    hardware ethernet 00:14:22:c3:38:53;
    uid "\001\000\024\"\3038S";
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:35:26;
    ends 3 2012/04/04 14:36:38;
    cltt 3 2012/04/04 14:35:26;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:02;
    ends 3 2012/04/04 14:37:14;
    cltt 3 2012/04/04 14:36:02;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:38;
    ends 3 2012/04/04 14:37:50;
    cltt 3 2012/04/04 14:36:38;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Si si, la commande marche très bien :
      $ sed -n '/^binding state free/{:z;n;/^hardware/! bz;p}' fic 
      hardware ethernet 00:20:d2:25:54:23;
      hardware ethernet 00:14:22:c3:38:53;


      Et à la limite, on peut faire comme ceci aussi :
      $ sed -n '/^binding state free/,/^hardware/{/binding state free/b;/hardware/p}' fic 
      hardware ethernet 00:20:d2:25:54:23;
      hardware ethernet 00:14:22:c3:38:53;
      0
  13. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    merci pour ta réponse mais je vous assure qu'avec ce fichier la:il affiche rien .

    merci d'avance
    lease 192.168.100.10 {
    starts 3 2012/03/28 08:01:45;
    ends 3 2012/03/28 08:11:45;
    tstp 3 2012/03/28 08:11:45;
    cltt 3 2012/03/28 08:01:45;
    binding state free;
    hardware ethernet 00:20:d2:25:54:23;
    }
    lease 192.168.100.2 {
    starts 1 2012/04/02 09:54:36;
    ends 1 2012/04/02 09:55:48;
    tstp 1 2012/04/02 09:55:48;
    cltt 1 2012/04/02 09:54:36;
    binding state free;
    hardware ethernet 00:14:22:c3:38:53;
    uid "\001\000\024\"\3038S";
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:35:26;
    ends 3 2012/04/04 14:36:38;
    cltt 3 2012/04/04 14:35:26;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:02;
    ends 3 2012/04/04 14:37:14;
    cltt 3 2012/04/04 14:36:02;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:38;
    ends 3 2012/04/04 14:37:50;
    cltt 3 2012/04/04 14:36:38;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Affiche la sortie de :

      cat -A ton_fichier
      0
  14. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    merci pour ta réponse
    voila le fichier c'est un peu long vu que c'est un fichier log mais ca tourne toujours sur le même principe
    par contre ca marche avec d'autre fichier et d'autre ca marche pas
    merci d'avance de ton aide

    # The format of this file is documented in the dhcpd.leases(5) manual page.
    # This lease file was written by isc-dhcp-V3.1.3

    lease 192.168.100.10 {
    starts 3 2012/03/28 08:01:45;
    ends 3 2012/03/28 08:11:45;
    tstp 3 2012/03/28 08:11:45;
    cltt 3 2012/03/28 08:01:45;
    binding state free;
    hardware ethernet 00:20:d2:25:54:23;
    }
    lease 192.168.100.2 {
    starts 1 2012/04/02 09:54:36;
    ends 1 2012/04/02 09:55:48;
    tstp 1 2012/04/02 09:55:48;
    cltt 1 2012/04/02 09:54:36;
    binding state free;
    hardware ethernet 00:14:22:c3:38:53;
    uid "\001\000\024\"\3038S";
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:35:26;
    ends 3 2012/04/04 14:36:38;
    cltt 3 2012/04/04 14:35:26;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1b;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:02;
    ends 3 2012/04/04 14:37:14;
    cltt 3 2012/04/04 14:36:02;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1d;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:36:38;
    ends 3 2012/04/04 14:37:50;
    cltt 3 2012/04/04 14:36:38;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1f;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:37:14;
    ends 3 2012/04/04 14:38:26;
    cltt 3 2012/04/04 14:37:14;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:37:50;
    ends 3 2012/04/04 14:39:02;
    cltt 3 2012/04/04 14:37:50;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:38:26;
    ends 3 2012/04/04 14:39:38;
    cltt 3 2012/04/04 14:38:26;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:39:02;
    ends 3 2012/04/04 14:40:14;
    cltt 3 2012/04/04 14:39:02;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:39:38;
    ends 3 2012/04/04 14:40:50;
    cltt 3 2012/04/04 14:39:38;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:40:14;
    ends 3 2012/04/04 14:41:26;
    cltt 3 2012/04/04 14:40:14;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:40:50;
    ends 3 2012/04/04 14:42:02;
    cltt 3 2012/04/04 14:40:50;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:41:26;
    ends 3 2012/04/04 14:42:38;
    cltt 3 2012/04/04 14:41:26;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:42:02;
    ends 3 2012/04/04 14:43:14;
    cltt 3 2012/04/04 14:42:02;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:42:38;
    ends 3 2012/04/04 14:43:50;
    cltt 3 2012/04/04 14:42:38;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:43:14;
    ends 3 2012/04/04 14:44:26;
    cltt 3 2012/04/04 14:43:14;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:43:50;
    ends 3 2012/04/04 14:45:02;
    cltt 3 2012/04/04 14:43:50;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:44:26;
    ends 3 2012/04/04 14:45:38;
    cltt 3 2012/04/04 14:44:26;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    lease 192.168.100.14 {
    starts 3 2012/04/04 14:45:02;
    ends 3 2012/04/04 14:46:14;
    cltt 3 2012/04/04 14:45:02;
    binding state active;
    next binding state free;
    hardware ethernet 00:20:d2:2b:f6:1a;
    }
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Ça ce n'est pas ce que je t'ai demandé ;-(

      Merci de relire le message précédent et d'afficher le résultat de la commande demandée !
      0
  15. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    Ok je vois
    voila le cat -A
    merci d'avance

    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:36:02;$
    ends 3 2012/04/04 14:37:14;$
    binding state free;$
    next binding state free;$
    hardware ethernet 44:20:d2:2b:f6:1a;$
    $
    $
    $
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:36:02;$
    ends 3 2012/04/04 14:37:14;$
    $
    binding state free;$
    next binding state free;$
    hardware ethernet 45:20:d2:2b:f6:1a;$
    $
    $
    $
    lease 192.168.100.10 {$
    starts 3 2012/03/28 08:01:45;$
    ends 3 2012/03/28 08:11:45;$
    binding state free;$
    next binding state free;$
    hardware ethernet 00:20:d2:25:54:23;$
    }$
    $
    lease 192.168.100.2 {$
    starts 1 2012/04/02 09:54:36;$
    ends 1 2012/04/02 09:55:48;$
    $
    $
    binding state free;$
    hardware ethernet 00:14:22:c3:38:53;$
    uid "\001\000\024\"\3038S";$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:35:26;$
    ends 3 2012/04/04 14:36:38;$
    $
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:36:02;$
    ends 3 2012/04/04 14:37:14;$
    cltt 3 2012/04/04 14:36:02;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    $
    root@BABALLE-01:~# sed -n '/^binding state free/,/^hardware/{/binding state free/b;/hardware/p}' f4
    root@BABALLE-01:~# cat -A f4
    # The format of this file is documented in the dhcpd.leases(5) manual page.$
    # This lease file was written by isc-dhcp-V3.1.3$
    $
    lease 192.168.100.10 {$
    starts 3 2012/03/28 08:01:45;$
    ends 3 2012/03/28 08:11:45;$
    tstp 3 2012/03/28 08:11:45;$
    cltt 3 2012/03/28 08:01:45;$
    binding state free;$
    hardware ethernet 00:20:d2:25:54:23;$
    }$
    lease 192.168.100.2 {$
    starts 1 2012/04/02 09:54:36;$
    ends 1 2012/04/02 09:55:48;$
    tstp 1 2012/04/02 09:55:48;$
    cltt 1 2012/04/02 09:54:36;$
    binding state free;$
    hardware ethernet 00:14:22:c3:38:53;$
    uid "\001\000\024\"\3038S";$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:35:26;$
    ends 3 2012/04/04 14:36:38;$
    cltt 3 2012/04/04 14:35:26;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1b;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:36:02;$
    ends 3 2012/04/04 14:37:14;$
    cltt 3 2012/04/04 14:36:02;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1d;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:36:38;$
    ends 3 2012/04/04 14:37:50;$
    cltt 3 2012/04/04 14:36:38;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1f;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:37:14;$
    ends 3 2012/04/04 14:38:26;$
    cltt 3 2012/04/04 14:37:14;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:37:50;$
    ends 3 2012/04/04 14:39:02;$
    cltt 3 2012/04/04 14:37:50;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:38:26;$
    ends 3 2012/04/04 14:39:38;$
    cltt 3 2012/04/04 14:38:26;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:39:02;$
    ends 3 2012/04/04 14:40:14;$
    cltt 3 2012/04/04 14:39:02;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:39:38;$
    ends 3 2012/04/04 14:40:50;$
    cltt 3 2012/04/04 14:39:38;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:40:14;$
    ends 3 2012/04/04 14:41:26;$
    cltt 3 2012/04/04 14:40:14;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:40:50;$
    ends 3 2012/04/04 14:42:02;$
    cltt 3 2012/04/04 14:40:50;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:41:26;$
    ends 3 2012/04/04 14:42:38;$
    cltt 3 2012/04/04 14:41:26;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:42:02;$
    ends 3 2012/04/04 14:43:14;$
    cltt 3 2012/04/04 14:42:02;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:42:38;$
    ends 3 2012/04/04 14:43:50;$
    cltt 3 2012/04/04 14:42:38;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:43:14;$
    ends 3 2012/04/04 14:44:26;$
    cltt 3 2012/04/04 14:43:14;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:43:50;$
    ends 3 2012/04/04 14:45:02;$
    cltt 3 2012/04/04 14:43:50;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:44:26;$
    ends 3 2012/04/04 14:45:38;$
    cltt 3 2012/04/04 14:44:26;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    lease 192.168.100.14 {$
    starts 3 2012/04/04 14:45:02;$
    ends 3 2012/04/04 14:46:14;$
    cltt 3 2012/04/04 14:45:02;$
    binding state active;$
    next binding state free;$
    hardware ethernet 00:20:d2:2b:f6:1a;$
    }$
    $
    $
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Ben je viens de refaire un test avec ton fichier et chez moi le résultat est toujours bon :

      $ sed -n '/^binding state free/,/^hardware/{/binding state free/b;/hardware/p}' fich
      hardware ethernet 00:20:d2:25:54:23;
      hardware ethernet 00:14:22:c3:38:53;

      Sur quel système es-tu ?
      Si GNU/Linux, quelle distrib ?
      Quelle version de "sed" (sed --version) ?
      0
  16. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    c'est pas possible je sais pas c'est quoi le probleme
    voila les infos mais je pense pas que ca vient de la

    d'ailleurs je sais pas est ce que un script perl peux supporter une commande sed si nom je sais pas est ce qu'il aura une alternative en perl (script perl)
    merci d'avance
    version linux
    2.6.32-37-server #81-Ubuntu SMP Fri Dec 2 20:49:12 UTC 2011 x86_64 GNU/Linux
    version sed
    GNU sed version 4.2.1
    Copyright (C) 2009 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
    to the extent permitted by law.

    GNU sed home page: <http://www.gnu.org/software/sed/>.
    General help using GNU software: <http://www.gnu.org/gethelp/>.
    E-mail bug reports to: <bug-gnu-utils@gnu.org>.
    Be sure to include the word ''sed'' somewhere in the ''Subject:'' field.
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Bizarre tout ça :-\

      Est-ce que cette simple commande te retourne quelque chose ???
      $ sed -n '/^binding state free/p' f4
      binding state free;
      binding state free;


      Pour Perl il faudrait adapter la commande "sed", par contre n'y connaissant rien en Perl, je ne pourrai t'être d'un grand secours ;-(
      0
  17. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    avec une fichier(nomé h) qui contient:
    root@BABALLE-01:~# cat -A h
    lease 192.168.100.10 {$
    starts 3 2012/03/28 08:01:45;$
    ends 3 2012/03/28 08:11:45;$
    tstp 3 2012/03/28 08:11:45;$
    cltt 3 2012/03/28 08:01:45;$
    binding state free;$
    hardware ethernet 22:20:d2:25:54:23;$
    }$
    lease 192.168.100.2 {$
    starts 1 2012/04/02 09:54:36;$
    ends 1 2012/04/02 09:55:48;$
    tstp 1 2012/04/02 09:55:48;$
    cltt 1 2012/04/02 09:54:36;$
    binding state free;$
    hardware ethernet 33:14:22:c3:38:53;$
    uid "\001\000\024\"\3038S";$
    }$
    $

    il affiche rien:

    root@BABALLE-01:~# sed -n '/^binding state free/,/^hardware/{/binding state free/b;/hardware/p}' h
    root@BABALLE-01:~#

    merci d'avance.
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Peux-tu mettre ton fichier sur Cjoint s'il te plaît, merci ?
      0
  18. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    voila un exemple
    https://www.cjoint.com/?BDlmtdLPea2
    c'est le fichier h avec qui j'ai essayé
    merci d'avance
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      Voilà le problème, les fins de lignes à la sauce Micro$oft ;-((

      cat -A h.txt 
      lease 192.168.100.10 {^M$
        starts 3 2012/03/28 08:01:45;^M$
        ends 3 2012/03/28 08:11:45;^M$
        tstp 3 2012/03/28 08:11:45;^M$
        cltt 3 2012/03/28 08:01:45;^M$
        binding state free;^M$
        hardware ethernet 22:20:d2:25:54:23;^M$
      }^M$
      lease 192.168.100.2 {^M$
        starts 1 2012/04/02 09:54:36;^M$
        ends 1 2012/04/02 09:55:48;^M$
        tstp 1 2012/04/02 09:55:48;^M$
        cltt 1 2012/04/02 09:54:36;^M$
        binding state free;^M$
        hardware ethernet 33:14:22:c3:38:53;^M$
        uid "\001\000\024\"\3038S";^M$
      }^M$
      ^M$

      D'une part, et d'autre part, c'est les espaces devant les lignes ;-((

      Donc après avoir converti ton fichier au format Unix (dos2unix h.txt), essayer cette syntaxe :
      sed -n '/^  *binding state free/,/^hardware/{/binding state free/b;/hardware/p}' h.txt 

      Attention, il y a 2 espaces avant l'astérisque.
      0
  19. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    super la ca marche pour l'instant
    pourrai je avoir quelque explications de la commande sed parce que j'avoue que sed c'est pas du tt mon truc que t'avais utilisé
    merci d'avance
    0
    1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 502
       
      -n
      Seule les informations qui nous intéressent seront affichées. Cette option marche avec le flag "p" que nous trouverons plus loin


      /^ *binding state free/,/^hardware/
      On sélectionne les lignes comprises dans l'intervalle correspondant aux deux motifs, chaque motif étant encadré par des slashs (/) et séparé par une virgule).
      Le 1er doit commencer (^) par 2 espaces ou plus ( *) puis la chaîne de caractères "binding state free", et le 2nd doit commencer (^) par la chaîne de caractères "hardware"


      {
      Début du regroupement de commandes. Toutes les instructions qui se trouvent entre les 2 accolades s'appliqueront à l'intervalle visé.


      /binding state free/b
      Si la ligne contient le motif, ne rien faire et se brancher (commande "b") à la fin du script


      /hardware/p
      Si la ligne contient le motif, alors l'imprimer (commande "p")


      }
      Fin du regroupement de commandes
      0
  20. othmane19 Messages postés 96 Date d'inscription   Statut Membre Dernière intervention  
     
    un grand merci
    0
Précédent
  • 1
  • 2