function addLine() { confFile=configuration.xml isExist=`cat ${confFile} | grep "<listen_enable>"` if [ "X" == "X${isExist}" ] then # 在<listen_port>后追加<listen_enable>行 sed -i '/<listen_port>/a\ <lis
用类方法和静态方法实现:一个是追加写文件一行内容,一个是读指定行号的内容 #coding=utf-8 class handle_file(object): def __init__(self,file_path): self.file_path=file_path @classmethod def write_file(cls,file_path,content): with open(file_path,'a') as
input为sed输入文件,内容如下: [root@node1 gitlab-test-]# cat inppu.txt aa bb cc dd 追加文本: 1.匹配 aa 行之后追加文本 We append a new line. [root@node1 gitlab-test-]# sed '/aa/a\We append a new line.' inppu.txt aa bb cc dd We append a new line. #说明已经匹配到了aa 后在 aa行下追加了 We