Sed ajout en fin de commande script shell

Résolu
titoulevrai -  
 titoulevrai -
Bonjour,

Je travail sur un script et j'ai besoin en sed de rajouter en fin de ligne de chaque ligne de commande un "debug".
Je voudrai que le script:
echo lolpass1 

ping 127.0.0.1 -c 2

echo testcom #commentaires

echo "test"


Se transforme en:
echo lolpass1  && echo "echo lolpass1  : OK" >>result.txt || echo "echo lolpass1 " >> $errors

ping 127.0.0.1 -c 2 && echo "ping 127.0.0.1 -c 2 : OK" >>result.txt || echo "ping 127.0.0.1 -c 2" >> $errors

echo testcom && echo "echo testcom: OK" >>result.txt || echo "echo testcom" >> errors.txt#commentaires

echo "test" && echo "echo "test" : OK" >>result.txt || echo "echo "test"" >> errors.txt

Les difficultés principales que j'ai c'est la gestion de quillemets, les lignes vides et la gestion des commentaires.
Merci d'avance

1 réponse

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

    $ cat brol
    echo lolpass1

    ping 127.0.0.1 -c 2

    echo testcom #commentaires

    echo "test"


    $ sed "/^$/! s/^[^#]*/& \&\& echo '& : OK' >> result.txt || echo '&' >> errors.log/" brol
    echo lolpass1 && echo 'echo lolpass1 : OK' >> result.txt || echo 'echo lolpass1' >> errors.log

    ping 127.0.0.1 -c 2 && echo 'ping 127.0.0.1 -c 2 : OK' >> result.txt || echo 'ping 127.0.0.1 -c 2' >> errors.log

    echo testcom && echo 'echo testcom : OK' >> result.txt || echo 'echo testcom ' >> errors.log#commentaires

    echo "test" && echo 'echo "test" : OK' >> result.txt || echo 'echo "test"' >> errors.log


    ;-))
    0
    1. titoulevrai
       
      Merci beaucoup!
      0