sed edit file in place

前端 未结 13 1655
忘掉有多难
忘掉有多难 2020-11-22 05:20

I am trying to find out if it is possible to edit a file in a single sed command without manually streaming the edited content into a new file and

13条回答
  •  有刺的猬
    2020-11-22 06:03

    The following works fine on my mac

    sed -i.bak 's/foo/bar/g' sample
    

    We are replacing foo with bar in sample file. Backup of original file will be saved in sample.bak

    For editing inline without backup, use the following command

    sed -i'' 's/foo/bar/g' sample
    

提交回复
热议问题