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

Applications et environnements graphiques Discussion :

join unix command


Sujet :

Applications et environnements graphiques

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 10
    Points : 8
    Points
    8
    Par défaut join unix command
    Hello,

    I have for instance these 2 files :

    file1
    1
    2
    3

    file2
    4
    5
    6

    Can I with join command have an output file3 like :
    1 4
    2 5
    3 6


    Thx in advance for help,

  2. #2
    Membre expert Avatar de jabbounet
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Juin 2009
    Messages
    1 909
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Juin 2009
    Messages : 1 909
    Points : 3 284
    Points
    3 284
    Par défaut
    Something like this should solve what you described (this sample uses two input files A.txt and B.txt)

    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
     
    #!/bin/bash
     
    awk  '
      BEGIN {
              # load array with contens f1.txt
              while ( getline < "A.txt" > 0 )
                {
                  f1_counter++
                  f1[f1_counter] = $1
                }
      }
      { 
        # 
        print $1 " " f1[NR]
       } ' B.txt

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 10
    Points : 8
    Points
    8
    Par défaut
    Thx for the reply.

    But I want to see if it is possible to do it with join command and it is options maybe.

    Do you have an idea about it ?

  4. #4
    Membre expert Avatar de jabbounet
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Juin 2009
    Messages
    1 909
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Juin 2009
    Messages : 1 909
    Points : 3 284
    Points
    3 284
    Par défaut
    for join command you need a common field present on both file

    basically join will give you this
    file1
    1 A
    2 B
    3 C

    file 2
    1 E
    2 F
    3 G

    join file1 file2
    AE
    BF
    GC
    options of join will provide some tweak about field separators, key to use in both files, or formatting the output.

    you will fine an explanation on how this work here
    http://www.softpanorama.org/Tools/join.shtml

  5. #5
    Membre expert Avatar de jabbounet
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Juin 2009
    Messages
    1 909
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Juin 2009
    Messages : 1 909
    Points : 3 284
    Points
    3 284
    Par défaut
    An other unix command provides what you want.

    This is the paste command.

    http://unixhelp.ed.ac.uk/CGI/man-cgi?paste

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    sh-3.1$ cat A.txt
    1 1
    2 2
    3 3
    sh-3.1$ cat B.txt
    1 A
    2 B
    3 C
    sh-3.1$ paste A.txt B.txt
    1 1     1 A
    2 2     2 B
    3 3     3 C

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 10
    Points : 8
    Points
    8
    Par défaut
    ok, thx a million for these info.

    Regs,

Discussions similaires

  1. RoR et unix commande
    Par WBO dans le forum Ruby
    Réponses: 1
    Dernier message: 12/06/2015, 10h59
  2. [shell unix] Commande sed
    Par Michel38 dans le forum Shell et commandes POSIX
    Réponses: 3
    Dernier message: 31/08/2011, 15h15
  3. Unix - commande cpio, ajout fichier à archive
    Par Math38 dans le forum Unix
    Réponses: 1
    Dernier message: 26/08/2008, 20h31
  4. [Unix] Commande Unzip
    Par Hoegaarden dans le forum Linux
    Réponses: 7
    Dernier message: 26/02/2008, 14h33
  5. Unix Commande SPADMIN
    Par hammag dans le forum Administration système
    Réponses: 2
    Dernier message: 17/08/2007, 14h58

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