How to replace a value with the output of a command in a text file?

后端 未结 2 1643
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 16:12

I have a file that contains:

I want to replace in bash, the value 0

2条回答
  •  -上瘾入骨i
    2020-12-09 16:38

    When the replacement string has newlines and spaces, you can use something else. We will try to insert the output of ls -l in the middle of some template file.

    awk 'NR==FNR {a[NR]=$0;next}
        {print}
        /Insert index here/ {for (i=1; i <= length(a); i++) { print a[i] }}'
        <(ls -l) template.file
    

    or

    sed '/^Insert after this$/r'<(ls -l) template.file
    

提交回复
热议问题