Sed ajout en fin de commande script shell

Résolu/Fermé
titoulevrai - Modifié le 16 août 2018 à 13:18
 titoulevrai - 16 août 2018 à 13:47
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

zipe31 Messages postés 36402 Date d'inscription dimanche 7 novembre 2010 Statut Contributeur Dernière intervention 27 janvier 2021 6 407
16 août 2018 à 13:31
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
Merci beaucoup!
0