1
qakito 2021-01-08 09:29:41 +08:00
uci 配置文件有提供统一的读写接口:
Usage: uci [<options>] <command> [<arguments>] Commands: batch export [<config>] import [<config>] changes [<config>] commit [<config>] add <config> <section-type> add_list <config>.<section>.<option>=<string> del_list <config>.<section>.<option>=<string> show [<config>[.<section>[.<option>]]] get <config>.<section>[.<option>] set <config>.<section>[.<option>]=<value> delete <config>[.<section>[[.<option>][=<id>]]] rename <config>.<section>[.<option>]=<name> revert <config>[.<section>[.<option>]] reorder <config>.<section>=<position> Options: -c <path> set the search path for config files (default: /etc/config) -d <str> set the delimiter for list values in uci show -f <file> use <file> as input instead of stdin -m when importing, merge data into an existing package -n name unnamed sections on export (default) -N don't name unnamed sections -p <path> add a search path for config change files -P <path> add a search path for config change files and use as default -q quiet mode (don't print error messages) -s force strict mode (stop on parser errors, default) -S disable strict mode -X do not use extended syntax on 'show' |
2
Raos 2021-01-08 09:36:45 +08:00
sed '/local/d'
|
3
lihuoqingfly 2021-01-08 09:41:29 +08:00
参考手册: https://quickref.me/sed
|
4
IgniteWhite 2021-01-08 09:45:47 +08:00 via iPhone
你还可以试试 awk 啊
|
7
zent00 2021-01-08 09:51:20 +08:00
比如删除 option rebind_localhost '1' 这一行:
sed -i "/option rebind_localhost '1'/d" dnsmasq.conf |
8
IgniteWhite 2021-01-08 09:56:11 +08:00 via iPhone 1
看了楼主在 5 楼的代码,我只能说
君 regex 本当上手 另外根据你系统不一样,shell 不一样,有时候要用 sed -e,有时候对于双引号的严格性也不同。这些信息也不写在问题里…… |
9
IgniteWhite 2021-01-08 09:59:34 +08:00 via iPhone
纠正,是-E,不是小写
|
10
6IbA2bj5ip3tK49j 2021-01-08 10:17:25 +08:00 via iPhone
目测一楼才是正解
|
12
Raos 2021-01-08 10:30:47 +08:00
@lihuoqingfly 收藏了
|
13
tachikomachann 2021-01-08 10:51:30 +08:00 via Android
sed 不知道,但是 vim 的话,用 g 命令可以
:g/要匹配的关键字 /d |
14
aibangjuxin 2021-01-08 12:24:04 +08:00
考虑效率?
cat a|sed -e '/./{H;$!d;}' -e 'x;/dnsmasq/!d;'|sed '/domainneeded/d' domainneeded 为要删除的行 |
15
doumeki 2021-01-08 16:41:47 +08:00
说个题外话,如果是编译之前自定义,还是写成 patch 吧。
运行时的话使用一楼说的 uci. PS: 我自己写了改了几十个编译自定义文件,全是用的 patch 方式。 |
16
fo0o7hU2tr6v6TCe 2021-01-08 17:18:32 +08:00
cat xx | sed "/option leasefile '\/tmp\/dhcp.leases'/d"
|
17
byaiu 2021-01-08 19:26:24 +08:00 via iPhone
忘了-i 了吧
|