Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the common templates for sed tools in linux?

Shulou Source: shulou.com Published: 2022-06-03 05:35:31 09月25日 Update

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 _

Tags: Parameters openings files text tools commonly used templates powerful functional instructions dates comments followed by scripts processing work uprising Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Huawei macOS Docker