Find and replace in file and overwrite file doesn't work, it empties the file

后端 未结 13 2362
深忆病人
深忆病人 2020-11-22 08:45

I would like to run a find and replace on an HTML file through the command line.

My command looks something like this:

sed -e s/STRING_TO_REPLACE/STR         


        
13条回答
  •  青春惊慌失措
    2020-11-22 09:36

    I was searching for the option where I can define the line range and found the answer. For example I want to change host1 to host2 from line 36-57.

    sed '36,57 s/host1/host2/g' myfile.txt > myfile1.txt
    

    You can use gi option as well to ignore the character case.

    sed '30,40 s/version/story/gi' myfile.txt > myfile1.txt
    

提交回复
热议问题