Use sed command to replace file file content under Linux

  

Sed tool is very powerful, powerful to the manual of the command can produce a book with more than 1000 pages. However, Want Want only said one function that I often use, [replace], there are mainly the following ways to use: 1, replace and output (do not modify the source file): sed 's/dog/cat/g' file ##dog The content to be replaced, the content replaced by cat 2, directly replaced with the source file after backup: sed -i.bak 's/dog/cat/g' file3, replace the nth line to the mth line: sed 'n, ms/Dog/cat/g' file ##n, m is the number 4, the content between the replacement content xxx and ***: sed '/A/, /B/s/dog/cat/g' file ##换A Content between and B, replace multiple pieces at a time: sed -e 's/dog1/cat1/g' -e 's/dog2/cat2/g' file

Copyright © Windows knowledge All Rights Reserved