简体   繁体   English

如何使用Sed命令将文件精确地附加在最后一句的末尾

[英]How to append a file exactly at the tail of the last sentence using Sed command

I need to output a bash scripts in csv format, the output i wanted is as follow. 我需要以csv格式输出bash脚本,我想要的输出如下。 while i need to append file named 1.2.6.2.txt right after the tail of 1.2.6.1.txt and it cannot be a next row entry, preferred to finish this using sed command. 虽然我需要在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

And: 和:

#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)"

The output i needed: 我需要的输出:

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)
"

Already tried this command to able to append text right after the tail of a file 已经尝试过此命令能够在文件尾部之后附加文本

sed -e $'$s/$/:SUFFIX &/' result/1.2.6.1.txt sed -e $'$ s / $ /:SUFFIX&/'result / 1.2.6.1.txt

1.2.6 Disable Proxy Modules command to get result httpd -M | 1.2.6禁用代理模块命令以获取结果httpd -M | grep proxy_ expected result should be null:SUFFIX grep proxy_预期结果应为null:SUFFIX

But when i tried the command below, the e cat result/1.2.6.2 command which suppose to add the content of 1.2.6.2.txt after the original sentence doesn't work: 但是当我尝试下面的命令时,假设在原始句子后添加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}

You are getting that error because you need to escape the / character in {e cat result/1.2.6.2.txt} . 之所以出现该错误,是因为您需要转义{e cat result/1.2.6.2.txt}/字符。 So you could run it as follows: 因此,您可以按以下方式运行它:

sed -e $'s/$/{e cat result\/1.2.6.2.txt}/' result/1.2.6.1.txt

Without using sed , you can simply run: 无需使用sed ,您只需运行:

var1=$(cat result/1.2.6.1.txt)
var2=$(cat result/1.2.6.2.txt)
echo $var1$var2 >result/final.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM