Sortie de commande dans le modèle sed [duplicate]
Oct 02 2020
Est-il possible d'avoir une sortie de commande dans un modèle sed?
J'ai essayé ceci:
sed -i 's/pattern/${python script.py}/gI' file.txt
Réponses
2 lucasgvarela Oct 01 2020 at 23:58
Oui c'est possible.
$ cat file.txt pattern pattern aaaaa bbbbb $ cat python.py
print("hello")
$ python3 python.py hello $ echo $(python3 python.py) hello $ sed "s/pattern/$(python3 python.py)/gI" file.txt hello hello aaaaa bbbbb Edit: (based on the comments) adding one example of why you should not use single quote $ sed 's/pattern/$(python3 python.py)/gI' file.txt $(python3 python.py)
$(python3 python.py)
aaaaa
bbbbb
Edit2: I removed the flag -i in the sed to test, it's easier you don't change your file until you have the desired result. For the final solution you should use the sed -i to have the file changed.