sed edit file in place

前端 未结 13 2063
忘掉有多难
忘掉有多难 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 05:49

    mv file.txt file.tmp && sed 's/foo/bar/g' < file.tmp > file.txt
    

    Should preserve all hardlinks, since output is directed back to overwrite the contents of the original file, and avoids any need for a special version of sed.

提交回复
热议问题