Remplacer un caractère à travers shell

chiefNam Messages postés 7 Statut Membre -  
zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   -
bonjour Team,

j'essai de remplacer à partir d'un shell le caractère '\' suivi des retour à la ligne dans un fichier par le vide.

c'est a dire partir de ca



à

2 réponses

  1. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 501
     
    Salut,

    Il aurait été plus judicieux de nous faire un copier/coller d'un bout de ton fichier plutôt que de mettre des captures d'écran ;-(

    Un truc du genre devrait le faire (sous réserve qu'il n'y ait pas de caractères sournois dans ton fichier) :

    $ cat f1 
    qdqsdqsgd|klqsdq|qkhdqsklhdqskl \
    |hsdjkfhsjfh|kfjdfjsdk|||
    gjldmfjgldfm|glmdfgk|mjc \
    |fjsdkl|klsdf|||


    $ sed ':z;N;$!bz;s/\\\n/|/g' f1 
    qdqsdqsgd|klqsdq|qkhdqsklhdqskl ||hsdjkfhsjfh|kfjdfjsdk|||
    gjldmfjgldfm|glmdfgk|mjc ||fjsdkl|klsdf|||

    1
    1. chiefNam Messages postés 7 Statut Membre
       
      Salut @zipe31,

      Ci-dessous le contenu

      hhhth|yuiok,|fee|rtnjjk| |derf|xcvg| |ghjui|tgrfe|g|14/06/2018|huuj|uytr|5896,0|x|hikioujk \
      |Z|gtyyhju| | | | | | |896|hjyj|yjyj|| |rtj|rzrtyh| |h|r|e| ||rey|hyh|grry|ryy|hji,0|htrh|th|0| | |thj| |thtj| ||| | | | |
      jyjj|yj|rj|rtj| |rtj|rtj| |rtj|ffh|3|14/06/2018|9000|14/06/2018|33000,0|C|olppkh \
      |Z|gtyyhju| | | | | | |896|hjyj|yjyj|| |rtj|rzrtyh| |h|r|e| ||rey|hyh|grry|ryy|hji,0|htrh|th|0| | |thj| |thtj| ||| | | | |
      hhhth|yuiok,|fee|rtnjjk| |derf|xcvg| |ghjui|tgrfe|g|14/06/2018|huuj|uytr|5896,0|x|hikioujk \
      |Z|gtyyhju| | | | | | |896|hjyj|yjyj|| |rtj|rzrtyh| |h|r|e| ||rey|hyh|grry|ryy|hji,0|htrh|th|0| | |thj| |thtj| ||| | | | |
      jyjj|yj|rj|rtj| |rtj|rtj| |rtj|ffh|3|14/06/2018|9000|14/06/2018|33000,0|C|olppkh \
      |Z|gtyyhju| | | | | | |896|hjyj|yjyj|| |rtj|rzrtyh| |h|r|e| ||rey|hyh|grry|ryy|hji,0|htrh|th|0| | |thj| |thtj| ||| | | | |
      hhhth|yuiok,|fee|rtnjjk| |derf|xcvg| |ghjui|tgrfe|g|14/06/2018|huuj|uytr|5896,0|x|hikioujk \
      |Z|gtyyhju| | | | | | |896|hjyj|yjyj|| |rtj|rzrtyh| |h|r|e| ||rey|hyh|grry|ryy|hji,0|htrh|th|0| | |thj| |thtj| ||| | | | |
      jyjj|yj|rj|rtj| |rtj|rtj| |rtj|ffh|3|14/06/2018|9000|14/06/2018|33000,0|C|olppkh \
      |Z|gtyyhju| | | | | | |896|hjyj|yjyj|| |rtj|rzrtyh| |h|r|e| ||rey|hyh|grry|ryy|hji,0|htrh|th|0| | |thj| |thtj| ||| | | | |

      je souhaite avoir au rendu ceci:
      0
    2. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 501 > chiefNam Messages postés 7 Statut Membre
       
      Salut,

      Ben la commande donnée ci-dessus (
      sed ':z;N;$!bz;s/\\\n/|/g'
      ) fait exactement ce que tu veux ;-))
      0
    3. chiefNam Messages postés 7 Statut Membre
       
      Salut,
      j'ai essayé mais j'ai un Feedback, ci dessous la capture.
      0
    4. zipe31 Messages postés 34620 Date d'inscription   Statut Contributeur Dernière intervention   6 501 > chiefNam Messages postés 7 Statut Membre
       
      Sur quel système es-tu ? Quelle version de sed ?

      Essaie comme ça :
      sed -e ':z' -e 'N' -e '$!bz' -e 's/\\\n/|/g'
      0
    5. chiefNam Messages postés 7 Statut Membre
       
      la version du sed est sed 4.2.2.
      le systeme est win 10.
      je travaille à distance sur le serveur à travers le protocole de communication genero
      0
  2. cs_PaTaTe Messages postés 1471 Date d'inscription   Statut Contributeur Dernière intervention   503
     
    Bonjour,

    Je suis assez mauvais avec awk mais un truc du genre :

    awk 'BEGIN {ORS=" "} {print} END {print "\n"}' SOURCE

    SOURCE étant la chaîne à modifier
    0
    1. chiefNam Messages postés 7 Statut Membre
       
      Merci bcp,
      j'essai avec
      0