我需要以 csv 格式输出 bash 脚本,我想要的输出如下。虽然我需要在 1.2.6.1.txt 的尾部立即 append 名为 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代理_ 预期结果应为 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
关于linux - 如何使用 Sed 命令将文件准确地 append 到最后一句话的尾部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57868996/