Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief Analysis of the usage of sed with an example

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First of all, let's say we have a file called 123.txtmetallurgical cat to see that it contains something like this:

[root@func-lms-001 ~] # cat 123.txt jamescurry durantwadeyaoming messi [root@func-lms-001 ~] #

If we want to add lebron before james, then the sed statement is # sed-I'/ ^ james/s/ ^ / lebron / '123.txt, and if we want to add champion after curry, the statement is # sed-I' / ^ curry/s/$/ champion '123.txt.

After using the above two sentences, take a look at # cat to see the effect:

[root@func-lms-001 ~] # cat 123.txt lebron jamescurry champion! Durantwadeyaoming messi [root@func-lms-001 ~] #

Now we want to put the letter FMVP in front of durant, according to the above sentence to find the gourd painting, it should be: # sed-I'/ ^ durant/s/ ^ / FMVP / '123.txt. But I'm sorry, this sentence is wrong! Because ^ matches the meaning of the beginning durant, and let's take a look at durant which line begins with a space.

Then use liunx's regularity to match spaces, so the sentence becomes: # sed-I'/ ^\ s\ + durant/s/ ^ / FMVP/' 123.txt, ^\ s\ + this is the meaning of matching spaces in the rule.

# cat:

[root@func-lms-001 ~] # cat 123.txt lebron jamescurry champion FMVP durantwadeyaoming messi [root@func-lms-001 ~] #

So now it's easy to add "GOAL!!" after messi. The statement is # sed-I'/ ^\ s\ + messi/s/$/ GOAL!! / '123.txt.

Above we have practiced adding characters with / without spaces, let's see what to do if we want to add them in the middle.

For example, one day the tough operation and maintenance staff received an email from the developer PL, saying that "due to the security baseline requirements, it is now necessary to monitor the private network port." the specific requirement is to add the private network IP to the server.xml files in all modules containing tomcat.

The excerpts from the original server.xml are as follows:

Now add the intranet IP to this sentence and change it like this:

Could you tell me what to do?

Answer 1:

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report