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

What are the common templates for sed tools in linux?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Sed is a linux tool that can edit text according to instructions or scripts, and the text processing function is very powerful. This paper summarizes some sed templates commonly used in the work, which is convenient for everyone to use.

Replace 1. Replace all the aaa in the file to bbbsed-I's bbbsed AAA BBG'/ path/to/file2. Find the modification date of the file stat deploy | sed-n'/ ^ Modify.*/p' # find stat deploy | sed-n'/ ^ Modify.*/p' | grep-Eo ".... -..:..:." # extract Modification uprising 2. Find the aaa parameter and set it to offsed-I'/ ^ aaa/s/on/off/' / path/to/file

It can be used with grep to set parameters automatically.

Have_aaa=$ (grep aaa / path/to/file | sed'/ ^ #. * / d') # look for the existence of the aaa parameter if [!-z $have_aaa] Then # if there is sed-I'/ ^ aaa/s/on/off/' / path/to/file #, modify it to offelse # if there is no sed-I'/ ccc/an aaa off' / path/to/file #, add aaa off # sed-I'$a/aaa off' / path/to/file # under the ccc parameter, then add aaa offfi to filter out all comment lines cat / etc/my. Cnf | sed'/ ^ #. * / d' find and delete

Find the row that contains aaa and delete

Sed-I'/ aaa/d' / path/to/file insert append a / insert below the current line; I / insert above the current line; c / change the current line to the new

Insert something below the line at the beginning of ccc

Sed-I'/ ^ ccc/a something' / path/to/file

Append something to the line at the beginning of ccc

Sed-I'/ ^ ccc/s/$/something/' / path/to/file

Append something immediately after ccc

Sed-I's _

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