In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the sed command in the linux system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The sed command in Linux is powerful. Today we will describe in detail how to replace it with the sed command in Linux. Specifically, it can be divided into the following situations:
1) how to replace the content found for the first time
2) how to replace all the matching content in the full text
3) how to replace the contents of a line
4) how to replace the contents of multiple lines
5) how to save the sed replacement result to the original text
6) how to use multiple sed replacement conditions at the same time
7) how to use regular expressions.
1. Replace the content found for the first time. The command is as follows:
Sed's / content to be replaced / New content / 'File to be processed
As shown in the following figure, the first lowercase b is replaced with an uppercase B.
2. Replace everything that can match in the full text. The command is as follows:
Sed's / content to be replaced / New content / G' File to be processed
As shown in the following figure, all lowercase b is replaced with uppercase B.
3. Replace the contents of a line with the following command:
Sed 'line number c new content' files to be processed
As shown in the following figure, replace the second line with "new test!"
4. Replace the contents of multiple lines with the following command:
Sed 'start line number, end line number c new content' file to be processed
As shown in the figure below, replace lines 2 through 6 with "new test!"
5. The above replacement commands only display the replacement results on the screen. If you want to save the replacement results directly to the original text, you only need to add the-I parameter. This is shown in the following figure.
Sed-I's / content to be replaced / New content / G' File to be processed
6. Multiple sed commands can also be connected with the-e parameter to complete multiple operations at one time. As shown in the figure below, first replace lowercase a with uppercase A, and then replace the second line with "new test!"
7. In addition, regular expressions are allowed in both the replaced and the replaced parts of the sed command. For example, the following command replaces all numbers with "good".
Sed's / [0-9] / OK / g 'testFile2.txt
Note:
Before entering the Linux command, be sure to switch the input method to the English half-width symbol state. Copy the command from the Windows computer to the Linux Terminal execution, it is also possible to encounter incorrect format caused by the command execution error, then it is recommended to manually re-enter the characters, if you feel troublesome, you can only delete the command space and the last character, re-enter the space and the last character.
Thank you for reading! This is the end of this article on "how to use the sed command in the linux system". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.