linux - 如何使用 Sed 命令在最后一句的末尾添加一个文件
问题描述
我需要以 csv 格式输出 bash 脚本,我想要的输出如下。虽然我需要在 1.2.6.1.txt 的尾部之后附加名为 1.2.6.2.txt 的文件并且它不能是下一行条目,但最好使用 sed 命令完成此操作。
#cat result/1.2.6.1.txt
1.2.6 Disable Proxy Modules,command to get result httpd -M | grep proxy_,expected result should be null
和:
#cat result/1.2.6.2.txt
" proxy_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_scgi_module (shared)
proxy_wstunnel_module (shared)"
我需要的输出:
1.2.6 Disable Proxy Modules,command to get result httpd -M | grep proxy_,expected result should be null,"
proxy_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_scgi_module (shared)
proxy_wstunnel_module (shared)
"
已经尝试过此命令以在文件尾部之后附加文本
sed -e $'$s/$/:SUFFIX &/' 结果/1.2.6.1.txt
1.2.6 禁用代理模块命令以获取结果 httpd -M | grep proxy_ 预期结果应为 null:SUFFIX
但是当我尝试下面的命令时,假设在原句后添加 1.2.6.2.txt 内容的 e cat result/1.2.6.2 命令不起作用:
# sed -e $'$s/$/{e cat result\/1.2.6.2.txt}/' result/1.2.6.1.txt
1.2.6 Disable Proxy Modules
command to get result httpd -M | grep proxy_
expected result should be null{e cat result/1.2.6.2.txt}
解决方案
您收到该错误是因为您需要转义/
. {e cat result/1.2.6.2.txt}
所以你可以按如下方式运行它:
sed -e $'s/$/{e cat result\/1.2.6.2.txt}/' result/1.2.6.1.txt
不使用sed
,您可以简单地运行:
cat result/1.2.6.1.txt >> 1.2.6.2.txt
推荐阅读
- jpa - JPA 不生成 ddl 文件
- oracle - 动态查询中 v_MONTH 的标识符无效错误
- android - 如何捕获图像并裁剪它?
- excel - 在单元格更改时调用公式
- nginx - 如何在生产环境django+static+nginx中提供静态文件,如javascript css图像和pdf
- java - AccessDeniedException 如果使用 Files.find()
- python - 在重新索引 Series 时,值正在变为 NaN
- java - RecyclerView中视图的动态位置
- python - 如何访问 kivy 中的小部件?我需要通过按下按钮来删除 TextInput
- javascript - 除非页面刷新,否则表单每次都会出现验证错误