Output del comando nel pattern sed [duplicato]

Oct 02 2020

È possibile avere un output di comando in uno schema sed?

Ho provato questo:

sed -i 's/pattern/${python script.py}/gI' file.txt

Risposte

2 lucasgvarela Oct 01 2020 at 23:58

Si è possibile.

$ 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.