【发布时间】:2018-12-03 08:11:15
【问题描述】:
您好,我无法通过 sed 命令添加换行符。我被指示编写一个更新主机文件的命令。另外,我的 sed 命令是用 bash 脚本编写的,尽管它一直输出错误消息。它说“sed: -e expression #1, char 93: extra character after command.”
这是我想添加到我的主机文件中的内容。
# Gateway
10.0.0.1 schoolhost it20
# Addresses for the Windows
10.0.0.240 host1 it21
10.0.0.241 host2 it22
这是我在 bash 脚本中写的命令。
sed -i "/hosts/a \
\n# Gateway \
\n10.0.0.1 schoolhost it20 \
\n# Addresses for the Windows PCs \
\n10.0.0.240 host1 it21 \
\n10.0.0.241 host2 it22" hosts
【问题讨论】:
-
您只需要将这些确切的行附加到主机文件吗?
-
是的,即使是评论。主机文件的原始内容只有“localhost”。这个脚本假设更新它。它更像是一个备份脚本。
-
将您的文件上传到某处并发布链接。
-
ufile.io/9l5d4 用于 host_update。 ufile.io/5hn8pfor主机文件
-
您已使用 Windows 系统创建或编辑过该文件。
标签: bash sed text-processing