Linux Command Summary - Replace content

1, is replaced by the editor vim
vi / vim may be used: s command to replace the string.
: S / well / good / well to replace the current line is a good
: S / well / good / g in the current line is all well good
: N, $ s / well / good / replacing n-th row to the last row of the first well of each row is good
: N, $ s / well / good / g alternative n-th row to the last line of each row of all digital well as Good n, if n is expressed from the current row to the last row.
:% S / well / good / (equivalent to: g / well / s // good /) replacing the first well of each row is good
:% S / well / good / g (equivalent to: g / well / s // good / g) replacing each row are all well as good can be used as a delimiter #, whereby the intermediate appear / not as a delimiter
: S # well / # good / # replace the current line a well / as good /
:% s # / usr / bin # / bin # g can all paths file / usr / bin into / bin
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
16
. 17
2, and grep mating Sed
sed -i s/yyyy/xxxx/g `grep yyyy -rl --include="*.txt" ./`
Role: The string yyyy all txt files in the current directory (including subdirectories) in the Replace xxxx string. among them,
-i represents a file operation, `` grep command enclosed, showing the results of the grep command as an operation file.
s / yyyy / xxxx / yyyy indicates find and replace time is XXXX, showing the back row with a plurality g of yyyy are replaced, instead of replacing only the first
Further, if no subdirectories to find, only need to be replaced in the current directory, use sed command line command as follows: sed -is / XXXX / YYYY / G ./*.txt
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
. 3. find command to find and replace
find -name 'To find the name of the file' | xargs perl -pi -e 's | replaced string | replacement string | g' # find and replace a string containing the current directory and replace
find -name '* .txt' | xargs perl -pi -e 's | is replaced content | replace the contents of | g' # recursive search and replace
. find -type f -name '* .html ' | xargs perl -pi -e 's | is replaced content | replace the contents of
| G' ----------------
Copyright: this article is the original article CSDN bloggers "Ye silent", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/qq_25992179/article/details/82777486

Guess you like

Origin www.cnblogs.com/hanjiali/p/12059289.html