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 :

Ajouter des champs d'un fichier dans un autre fichier lorsqu'ils débutent par une même ligne


Sujet :

Shell et commandes GNU

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Novembre 2011
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2011
    Messages : 12
    Par défaut Ajouter des champs d'un fichier dans un autre fichier lorsqu'ils débutent par une même ligne
    Bonjour/Bonsoir

    Le titre n'est pas très clair alors je vous explique ce que j'aimerais arriver à faire.

    J'ai deux fichiers qui se présentent ainsi :

    fichier1 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    4store
    7kaa
    7kaa-data
    ...
    fichier2 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    2ping (1.1-1) [universe] Ping utility to determine directional packet loss
    3270-common (3.3.10ga4-2build1) [universe] Common files for IBM 3270 emulators and pr3287
    3depict (0.0.6-1) [universe] visualisation and analysis for single valued point data
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
    ...
    J'aimerais obtenir le fichier suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
    ...
    Malheureusement je ne sais pas du tout comment faire.

    Si quelqu'un avait une piste voire une solution à mon problème, je lui serais reconnaissant.

    edit : j'ai essayé avec join mais le résultat n'est pas satisfaisant.

  2. #2
    Modérateur
    Avatar de N_BaH
    Profil pro
    Inscrit en
    Février 2008
    Messages
    7 662
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 7 662
    Par défaut
    Bonjour,

    avec join […] le résultat n'est pas satisfaisant.
    pourquoi ?
    N'oubliez pas de consulter les cours shell, la FAQ, et les pages man.

  3. #3
    Expert confirmé

    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    1 946
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 1 946
    Par défaut
    Salut,

    Et avec "fgrep" ?

    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
    $ cat fich1
    4store
    7kaa
    7kaa-data
     
    $ cat fich2
    2ping (1.1-1) [universe] Ping utility to determine directional packet loss
    3270-common (3.3.10ga4-2build1) [universe] Common files for IBM 3270 emulators and pr3287
    3depict (0.0.6-1) [universe] visualisation and analysis for single valued point data
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
     
    $ fgrep -f fich1 fich2
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
     
    $

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Novembre 2011
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2011
    Messages : 12
    Par défaut
    Citation Envoyé par N_BaH Voir le message
    Bonjour,

    pourquoi ?
    Bonjour

    Parce qu'il y a des lignes qui passent "à la trappe"

    Je m'explique :

    wc -l fichier1
    wc -l fichier2
    join fichier1 fichier2 | wc -l
    Citation Envoyé par zipe31 Voir le message
    Salut,

    Et avec "fgrep" ?

    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
    $ cat fich1
    4store
    7kaa
    7kaa-data
     
    $ cat fich2
    2ping (1.1-1) [universe] Ping utility to determine directional packet loss
    3270-common (3.3.10ga4-2build1) [universe] Common files for IBM 3270 emulators and pr3287
    3depict (0.0.6-1) [universe] visualisation and analysis for single valued point data
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
     
    $ fgrep -f fich1 fich2
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
     
    $
    Ça ne marche pas non plus... Chez moi j'ai le résultat suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    2ping (1.1-1) [universe] Ping utility to determine directional packet loss
    3270-common (3.3.10ga4-2build1) [universe] Common files for IBM 3270 emulators a
    nd pr3287
    3depict (0.0.6-1) [universe] visualisation and analysis for single valued point 
    data
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- data
    base daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strateg
    y game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
    Ma version de bash :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $bash --version
    GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)

  5. #5
    Expert confirmé

    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    1 946
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 1 946
    Par défaut
    Euh... on peut avoir la sortie (ou un bout tout au moins) de cat -A fich1 et cat -A fich2 s'il te plaît, merci.

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Novembre 2011
    Messages
    12
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2011
    Messages : 12
    Par défaut
    J'ai mis les fichiers en questions sur un serveur FTP :

    http://demonipuch.free.fr/fichier1
    http://demonipuch.free.fr/fichier2

    Voici les 20 premières lignes de chaque fichiers :

    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
    $cat -A fichier1 | head -n 20
    4store$
    7kaa$
    7kaa-data$
    7kaa-dbg$
    aac-tactics$
    abacas$
    abgate$
    abrowser-zarafa-drag-n-drop$
    ac100-tarball-installer$
    acoustid-fingerprinter$
    activemq$
    aephea$
    afterstep-data$
    afterstep-dbg$
    agda$
    aglfn$
    aha$
    aj-snapshot$
    akonadi-backend-mysql$
    akonadi-backend-odbc$
    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
    $ cat -A fichier2 | head -n 20
    2ping (1.1-1) [universe] Ping utility to determine directional packet loss$
    3270-common (3.3.10ga4-2build1) [universe] Common files for IBM 3270 emulators and pr3287$
    3depict (0.0.6-1) [universe] visualisation and analysis for single valued point data$
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon$
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game$
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data$
    7kaa-dbg (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries - debug$
    a2jmidid (7-3) [universe] Daemon for exposing legacy ALSA MIDI in JACK MIDI systems$
    a56 (1.3-6) [universe] Motorola DSP56001 assembler$
    aac-tactics virtual package provided by libaac-tactics-coq$
    aajm (0.4-5ubuntu1) [universe] ASCII art version of jugglemaster$
    abacas (1.3.1-1) [universe] Algorithm Based Automatic Contiguation of Assembled Sequences$
    abcm2ps (5.9.22-1) [universe] Translates ABC music description files to PostScript$
    abe (1.1-4) [universe] Side-scrolling game named "Abe's Amazing Adventure"$
    abe-data (1.1-4) [universe] Side-scrolling game named "Abe's Amazing Adventure"$
    abgate (1.1.3-1) [universe] LV2 noise gate plugin$
    abinit (5.3.4.dfsg-3build2) [universe] A package for electronic structure calculations$
    abinit-doc (5.3.4.dfsg-3build2) [universe] A package for electronic structure calculations$
    abiword (2.8.6-0.3ubuntu2) [universe] efficient, featureful word processor with collaboration$
    abiword-common (2.8.6-0.3ubuntu2) [universe] efficient, featureful word processor with collaboration -- common files$
    Si vous avez besoin de plus de renseignements, n'hésitez pas.

    Merci

  7. #7
    Expert confirmé

    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    1 946
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 1 946
    Par défaut
    Je ne comprends pas

    En prenant exemple sur les deux bouts de fichiers fournis, j'obtiens bien le bon résultat :

    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
    $ bash --version
    GNU bash, version 4.1.5(2)-release (x86_64-mandriva-linux-gnu)
    Copyright (C) 2009 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
     
    This is free software; you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
     
    $ grep -V
    GNU grep 2.6.3
     
    Copyright (C) 2009 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
     
     
    $ grep -F -f fichier1 fichier2
    4store (1.1.3-1ubuntu2) [universe] RDF database storage and query engine -- database daemon
    7kaa (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries: real-time strategy game
    7kaa-data (2.13-1) [universe] Seven Kingdoms Ancient Adversaries - game data
    7kaa-dbg (2.14.3-1) [universe] Seven Kingdoms Ancient Adversaries - debug
    aac-tactics virtual package provided by libaac-tactics-coq
    abacas (1.3.1-1) [universe] Algorithm Based Automatic Contiguation of Assembled Sequences
    abgate (1.1.3-1) [universe] LV2 noise gate plugin
     
    $

Discussions similaires

  1. [XL-2003] Transcrire des données d'1 fichier dans d'autres fichiers
    Par Blgslb dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 11/06/2011, 18h02
  2. Réponses: 2
    Dernier message: 27/04/2009, 23h14
  3. Réponses: 4
    Dernier message: 28/08/2007, 17h11
  4. Réponses: 1
    Dernier message: 15/05/2007, 16h55
  5. Récupération des champs d'un form dans un autre
    Par Crazyblinkgirl dans le forum ASP
    Réponses: 10
    Dernier message: 22/06/2004, 10h31

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