我需要输出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/$/:后缀&/'结果/1.2.6.1.txt
1.2.6禁用代理模块
获取结果的命令httpd-M | grep proxy_
预期结果应为空:后缀
但是,当我尝试下面的命令时,e cat result/1.2.6.2命令(假设在原始语句之后添加1.2.6.2.txt的内容)不起作用:
# 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,您只需运行:
var1=$(cat result/1.2.6.1.txt)
var2=$(cat result/1.2.6.2.txt)
echo $var1$var2 >result/final.txt

关于linux - 如何使用Sed命令将文件精确地 append 在最后一句的末尾,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57868996/

10-14 16:26
查看更多