Example one:
The contents of the Config_file file are as follows:
- Sed removal Comment line: sed-i-c-e '/^#/d ' Config_file "deletes the specified file with comment lines"
- Sed to remove empty line: Sed-i-c-e '/^$/d ' config_file "Delete specified file blank line"
- Intercept content from 3 lines to end of line save as a file: Sed-n ' 3, $p ' Config_file >> Test.ini
- Delete content from line 1th to line 9 Save as file: Sed ' 1,9d ' config_file >> Test1.ini
Example two:
Assume that the configuration file yj.conf contains Test=no
- If you need to change "TEST" to AAABBB, as follows:
Sed-i '/test=/s/test/aaabbb/'/home/test/yj.conf
Result: "Pre-modification" Test=no = aaabbb=no "Modified"
- Delete configuration file yj.conf content test1=0
Sed-i/test1=/d/home/test/yj.conf
Result: Test1=no [This item will be deleted]
- Specify the line TEST1 before adding # as follows:
Sed-i '/test1=/s/test1/#&/' home/test/yj.conf
Result: "Pre-modification" Test1=no = #TEST1 =no "Modified"
- Specify line gateway next line Insert test=192.168.1.20
Sed-i "/gateway/a test=192.168.1.20"/home/test/yj.conf
The results are as follows:
gateway=192.168.10.31
test=192.168.1.20 [insert on this line]
- Specifies that the IP address of the line test is modified to 192.168.1.100, as follows:
Sed-i '/test=/s/192.168.1.20/192.168.1.100/'/home/test/yj.conf
Result: test=192.168.1.20 [modified to 192.168.1.100]
Linux commands (1): sed command