Extraction simple d'une chaine de caract

ZazNet -  
jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   -
Bonjour,

Je souhaite extraire de facon simple une chaine de caractères.
Exemple : 01256486696241255

Je veux extraire à partir du 5ème caractère sur 2 caractères.
Soit 48 dans l'exemple.

Comment faire ? Un awk, un cut ?

Merci beaucoup
Configuration: Windows XP
Internet Explorer 7.0

2 réponses

  1. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    Salut,
    [tmpfs]$ var="01256486696241255"
    [tmpfs]$ echo ${var:5:2}
    48
    [tmpfs]$
    ;-))
    0
    1. ZazNet
       
      J'ai oublié de preciser que je suis en train de lire un fichier de données.

      while read -r ligne
      do
      test=${ligne:21:4}

      ca ne fonctionne pas....
      pourquoi ? :(
      0
  2. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    J'en sais rien, faut voir ton fichier et la suite de ton script...
    [tmpfs]$ cat plop
    LIBELLE1
    LIBELLE2
    LIBELLE3
    LIBELLE4
    LIBELLE5
    LIBELLE6
    LIBELLE7
    LIBELLE8
    LIBELLE9
    [tmpfs]$ while read line; do echo ${line:2:5};done <plop
    BELLE
    BELLE
    BELLE
    BELLE
    BELLE
    BELLE
    BELLE
    BELLE
    BELLE
    [tmpfs]$
    ;-))
    0