sed edit file in place

前端 未结 13 2074
忘掉有多难
忘掉有多难 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:57

    Note that on OS X you might get strange errors like "invalid command code" or other strange errors when running this command. To fix this issue try

    sed -i '' -e "s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g" 
    

    This is because on the OSX version of sed, the -i option expects an extension argument so your command is actually parsed as the extension argument and the file path is interpreted as the command code. Source: https://stackoverflow.com/a/19457213

提交回复
热议问题