Afficher une ligne particulière d'un fichier

Résolu
moun -  
 andok -
bonjour

je voudrais savoir comment extraire ou afficher une ligne particulière d'un fichier en shell (par exemple : la ligne 3 du fichier toto) pour en faire une variable

merci

6 réponses

  1. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    Salut,

    Tu peux faire ça avec "sed" aussi:
    soit le fichier "fich"
    [jp@Mandrake scripts]$ cat fich
    
    nom_fichier_1 ; commentaire associé au fichier 1
    nom_fichier_2 ; commentaire associé au fichier 2
    nom_fichier_4 ; commentaire associé au fichier 4
    nom_fichier_5 ; commentaire associé au fichier 5
    nom_fichier_7 ; commentaire associé au fichier 7
    nom_fichier_9 ; commentaire associé au fichier 9
    nom_fichier_10 ; commentaire associé au fichier 10
    nom_fichier_12 ; commentaire associé au fichier 12
    nom_fichier_14 ; commentaire associé au fichier 14
    nom_fichier_15 ; commentaire associé au fichier 15
    nom_fichier_16 ; commentaire associé au fichier 16

    Pour extraire la 3 ème ligne
    [jp@Mandrake scripts]$ sed -n 3p fich
    nom_fichier_4 ; commentaire associé au fichier 4

    La 5 ème :
    [jp@Mandrake scripts]$ sed -n 5p fich
    nom_fichier_7 ; commentaire associé au fichier 7

    Pour la récupérer dans une variable :
    [jp@Mandrake scripts]$ var=`sed -n 5p fich`
    [jp@Mandrake scripts]$ echo $var
    nom_fichier_7 ; commentaire associé au fichier 7
    [jp@Mandrake scripts]$
    ;-))
    31
    1. andok
       
      Merci beaucoup mon cher.
      0