【已解决】求个sed命令 在文本开头插入内容

45次阅读

共计 1662 个字符,预计需要花费 5 分钟才能阅读完成。

查了半个钟 google 搞定了 谢谢各位 就知道 H20 素质差爱粗口伤人 现在注册了 HOH 还是那么颠
echo "# 高墙 List for RouterOS DNS with EVERYTHING included" > blocklist.rsc
echo "# Last Modified: $(date "+%Y-%m-%d %H:%M:%S")" >> blocklist.rsc
echo "#">> blocklist.rsc
echo "/ip/dns/static/remove [find type=FWD]" >> blocklist.rsc
echo "/ip dns static" >> blocklist.rsc
sed "s/^/add address-list= 扶墙 forward-to=1.1.1.1 match-subdomain=yes type=FWD name=&/g" /root/blocklist.txt >> blocklist.rsc 复制代码
文件 blocklist.rsc 内容如下
——————————————————————–
google.com
y2b.com

变成
——————————————————————–
# RouterOS Split DNS
# 创建时间
/ip/dns/static/remove [find type=FWD]
/ip dns static
add address-list=test forward-to=1.1.1.1 match-subdomain=yes type=FWD name=google.com
add address-list=test forward-to=1.1.1.1 match-subdomain=yes type=FWD name=y2b.com

你管这叫在文本开头插入内容?不会提问可以不要提问我网站有,挂上 t 打开 google.com

nkym 发表于 2022-12-6 21:22
我网站有,挂上 t 打开 google.com

那么请问行首加下面内容,该怎么办呢?
add address-list=test forward-to=1.1.1.1 match-subdomain=yes type=FWD name=
在文件开头插入文本
通过可在脚本中使用的 ed 单命令行程序,您可以容易地在文件开头插入文本。插入操作是使用 ed 并通过 a 命令将给定文本追加到第 0 行(文件开头)来完成的:
$ cat file
This is the end.
$ (echo ‘0a’; echo ‘This is the beginning.’; echo ‘.’; echo ‘wq’) | ed -s file
$ cat file
This is the beginning.
This is the end.
版权声明:本文为 CSDN 博主「tim_szchina」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/tim_szchina/article/details/83890501sed -e ‘1i # RouterOS Split DNSn# 创建时间 nn/ip/dns/static/remove [find type=FWD]n/ip dns static’ -e ‘s/^/add address-list=test forward-to=1.1.1.1 match-subdomain=yes type=FWD name=/g’ blocklist.rsc 复制代码
先看看打印的对不对,没问题在 sed 后面加一个 -i 参数就可以修改到 blocklist.rsc 这个文件了。

懒无止境丶 发表于 2022-12-6 21:55
先看看打印的对不对,没问题在 sed 后面加一个 -i 参数就可以修改到 blocklist.rsc 这个文件了。…

谢谢大佬 已经搞定了

正文完
 0