我有两个文件:domainList和config.cnf.domainList文件只有一个域列表,如下所示:
facebook.com
yahoo.com
youtube.com
Run Code Online (Sandbox Code Playgroud)
config.cnf是一个配置文件,具有相同的列表,格式略有不同.我需要编写一个脚本,在更新列表时更新配置文件.每当更新第一个列表时,我都可以执行bash脚本.这是配置文件中列表的格式......
*other config options/entries*
[my_list]
WWW.1 = facebook.com
WWW.2 = yahoo.com
WWW.3 = youtube.com
EOF
Run Code Online (Sandbox Code Playgroud)
所以,如果删除yahoo并在domainList中添加ebay并运行我的酷bash脚本,我需要更新配置文件...
*other config options/entries*
[my_list]
WWW.1 = facebook.com
WWW.2 = youtube.com
WWW.3 = ebay.com
EOF
Run Code Online (Sandbox Code Playgroud)
为了使事情(稍微)复杂化,域可以具有子域和外卡(即news.google.com或*.google.com).任何关于如何实现这一点的想法将不胜感激!如何在不弄清楚数据的情况下如何做到这一点?它可能只需要清除列表并每次都重新生成它,是吧?
谢谢!
EV
这是一个简单的脚本来实现:
# delete all lines after [my_list]
sed -i '/my_list/q' config.cnf
# add the domain list to the bottom of the config
awk '{print "WWW." NR " = " $0}' domainList >> config.cnf
Run Code Online (Sandbox Code Playgroud)
这个脚本可以写成带有awk或sed的单线程,但上面的(希望)它的方法非常清楚.