IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Shell et commandes GNU Discussion :

[shell] Extraction de chaines de caractères à partir d'un fichier txt


Sujet :

Shell et commandes GNU

  1. #1
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 50
    Points : 16
    Points
    16
    Par défaut [shell] Extraction de chaines de caractères à partir d'un fichier txt
    Bonjour à tous,

    J'ai un fichier txt qui contient plusieurs requêtes sql qui sont listées ci-dessous (au total y'en a 1600....). Ma problématique est la suivante, je cherche à isoler les requêtes qui créer les tablespaces en "dx" des requêtes qui créer des tablespaces en "ix" ?

    Afin d'avoir deux fichiers en sortie. Je pensai effectuer une recherche sur les mots clefs suivants : "oradbf/d" ou "oradbf/i" puis isoler la requête par la suite mais je n'ai pas de grande connaissance en shell...

    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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     CREATE TABLESPACE "ADM_ATA1" DATAFILE
      '/donnees/SANTEDQT/oradbf/d1/adm_ATA11.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 10485760 MAXSIZE 104857600
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "ADM_AIA1" DATAFILE
      '/donnees/SANTEDQT/oradbf/i1/adm_AIA11.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 10485760 MAXSIZE 104857600
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "STATSPACK" DATAFILE
      '/donnees/SANTEDQT/oradbf/d2/STATSPACK.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 10485760 MAXSIZE 209715200
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "IARCH" DATAFILE
      '/donnees/SANTEDQT/oradbf/i2/IARCH1.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 52428800 MAXSIZE 2097152000
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "ICMU" DATAFILE
      '/donnees/SANTEDQT/oradbf/i1/ICMU1.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 104857600 MAXSIZE 3000M
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "IIJ" DATAFILE
      '/donnees/SANTEDQT/oradbf/i1/IIJ1.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 104857600 MAXSIZE 5000M
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "INAT" DATAFILE
      '/donnees/SANTEDQT/oradbf/i6/INAT1.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 104857600 MAXSIZE 20000M
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "IREF2" DATAFILE
      '/donnees/SANTEDQT/oradbf/i7/IREF2.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 52428800 MAXSIZE 1048576000
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "TARCH" DATAFILE
      '/donnees/SANTEDQT/oradbf/d6/TARCH1.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 52428800 MAXSIZE 5000M
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "TCMU" DATAFILE
      '/donnees/SANTEDQT/oradbf/d5/TCMU1.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 52428800 MAXSIZE 3000M
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "TIJ" DATAFILE
      '/donnees/SANTEDQT/oradbf/d1/TIJ1.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 104857600 MAXSIZE 5000M
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "TIRDES" DATAFILE
      '/donnees/SANTEDQT/oradbf/d3/TIRDES.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 52428800 MAXSIZE 2097152000
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;
     
     
     
      CREATE TABLESPACE "TIND" DATAFILE
      '/donnees/SANTEDQT/oradbf/i3/tind.dbf' SIZE 100M
      AUTOEXTEND ON NEXT 10485760 MAXSIZE 1048576000
      LOGGING ONLINE PERMANENT BLOCKSIZE 32768
      EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO;


    Si vous aviez une idée pour m'aiguiller? Ou me dire si déjà je part dans la bonne direction ?


    Cdt,
    Matthieu

  2. #2
    Expert éminent Avatar de BufferBob
    Profil pro
    responsable R&D vidage de truites
    Inscrit en
    Novembre 2010
    Messages
    3 035
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : responsable R&D vidage de truites

    Informations forums :
    Inscription : Novembre 2010
    Messages : 3 035
    Points : 8 400
    Points
    8 400
    Par défaut
    salut,

    si tous tes enregistrements ont tous la même forme (5 lignes, le critère discriminant étant sur la 2e ligne à chaque fois), tu peux utiliser une tournure simple du style :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    grep -B1 -A3 -F 'oradbf/d' fichier | sed -e 's/^--//' > fichier_dx
    grep -B1 -A3 -F 'oradbf/i' fichier | sed -e 's/^--//' > fichier_ix
    • l'option -B1 de grep demande d'afficher 1 ligne avant (Before)celle qui match
    • l'option -A3 de la même manière demande d'afficher 3 lignes Après celle qui match
    • l'option -F permet simplement de faire une recherche de chaine fixe et accélérer un peu le traitement (optionnel donc)
    • le sed permet de faire disparaitre les délimiteurs laissés par grep juste avant

  3. #3
    Membre à l'essai
    Inscrit en
    Novembre 2007
    Messages
    50
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 50
    Points : 16
    Points
    16
    Par défaut
    merci pour ta réponse, je ne connaissais pas les options before et after de grep .

    C'est tout nickel.

  4. #4
    Expert éminent sénior Avatar de disedorgue
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Décembre 2012
    Messages
    4 278
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Décembre 2012
    Messages : 4 278
    Points : 12 726
    Points
    12 726
    Par défaut
    Bonjour,
    Une version en (gnu) sed:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sed -n -e '/CREATE/,/;/{H;b;}' -e 'x' -e '/oradbf\/i/w fichier1' -e '/oradbf\/d/w fichier2' fichier <(echo "")
    Le <(echo "") est là pour que la dernière ligne de 'fichier' ne soit pas celle qui contient le ';' sinon il ne traitera pas en compte le dernier bloc.
    Cordialement.

  5. #5
    Expert éminent sénior Avatar de Flodelarab
    Homme Profil pro
    Inscrit en
    Septembre 2005
    Messages
    5 243
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Charente (Poitou Charente)

    Informations forums :
    Inscription : Septembre 2005
    Messages : 5 243
    Points : 13 458
    Points
    13 458
    Par défaut
    Bonjour,

    oserai-je la version awk ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    awk 'BEGIN{RS=";";} /oradbf\/d/{print $0";">"fichier1";} /oradbf\/i/{print $0";">"fichier2";}' fichier
    Cette réponse vous apporte quelque chose ? Cliquez sur en bas à droite du message.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Extraction dans chaine de caractères variable
    Par ginkas31 dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 20/08/2007, 17h27
  2. Réponses: 5
    Dernier message: 26/04/2007, 15h39
  3. Extraction de chaine de caractères
    Par asterix76-rouen dans le forum Langage
    Réponses: 4
    Dernier message: 20/12/2006, 23h17
  4. Réponses: 2
    Dernier message: 05/01/2006, 13h15
  5. Remplacer dans une chaine de caractères à partir de la fin
    Par daddyel dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 02/01/2006, 11h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo