In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article is to share with you what the replacement command for linux is, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Linux replacement command: 1, use vim ": s / original content / replace content /" command to replace content; 2, use sed with grep to replace content; 3, use "find-name file name | xargs perl-pi-e's | original content | replace content | g'" command to replace content.
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is the linux replacement command?
1. Replace through the vim editor
The: s command can be used in vi/vim to replace strings.
: s/well/good/ replaces the current line with good as the first well
: s/well/good/g replaces all well in the current line to good
The first well of each line from the beginning of line n to the last line is good
All well in each line from the beginning of the nth line to the last line is the number good n. If n is., it means from the current line to the last line.
:% s/well/good/ (equivalent to: g/well/s//good/) replaces the first well of each line with good
:% s/well/good/g (equivalent to: g/well/s//good/g) replace all well in each line with good. You can use # as the delimiter, and the / that appears in the middle will not be the delimiter.
: s#well/#good/# replaces the current line with good/ as the first well/
:% s#/usr/bin#/bin#g can change all paths / usr/bin in the file to / bin
2. Sed and grep cooperate
Sed-I s/yyyy/xxxx/g `grep yyyy-rl-- include= "* .txt". / `
Purpose: replace yyyy strings with xxxx strings in all txt files in the current directory (including subdirectories). Among them
-I means the operation is a file, and the grep command enclosed by ``means that the result of the grep command is used as the operation file.
S/yyyy/xxxx/ means to find yyyy and replace it with xxxx, followed by g to indicate that when there are multiple yyyy in a line, all will be replaced instead of just the first one
In addition, if you don't need to find subdirectories, just replace them in the current directory and use the sed command, which is as follows: sed-I s/xxxx/yyyy/g. / * .txt
3.find command find and replace
Find-name 'File name to find' | xargs perl-pi-e's | replaced string | replaced string | g'
# find and replace the string contained in the current directory and replace
Find-name'* .txt'| xargs perl-pi-e's | content to be replaced | content to be replaced | G' # Recursive search to replace
Find. -type f-name'* .html'| xargs perl-pi-e's | replaced content | replaced content | g'
The above is what the replacement command of linux is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.