zoukankan      html  css  js  c++  java
  • shell将2个文件的前两行和最后一行中间内容合并的编写过程

      1-初步想法:将固定的头和尾写死追加到内容前后:

    echo -e '<?xml version="1.0"?>
    <doc>' >> c.txt 
    && cat a.txt | sed '1,2d' | sed '$d' >> c.txt 
    && cat b.txt | sed '1,2d' | sed '$d' >> c.txt 
    && echo '</doc>' >> c.txt

      2-改进用法:

    head -2 a.txt >> c.txt 
    && sed '1,2d' a.txt | sed '$d' >> c.txt 
    && sed '1,2d' b.txt | sed '$d' >> c.txt 
    && tail -n 1 a.txt >> c.txt

      重点命令: head、sed、tail。     符号: ">>"、"&&"、 "|" 、 ""

    附加:

      a.txt和b.txt文件:

    <!html>
    <html>
      <body>
          aaaa
      </body>
    </html>

      合并文件:

    <!html>
    <html>
      <body>
          aaaa
      </body>
      <body>
          bbb
      </body>
    </html>
    *感谢您的阅读。喜欢的、有用的就请大哥大嫂们高抬贵手“推荐一下”吧!你的精神 支持是博主强大的写作动力。欢迎转载!
    *博主的文章是自己平时开发总结的经验,由于博主的水平不高,不足和错误之处在所难免,希望大家能够批评指出。
    *我的博客: http://www.cnblogs.com/lxhbky/
  • 相关阅读:
    分数的表示和运算
    用户管理
    DML,DDL
    索引
    sql语句执行顺序
    伪劣
    序列
    视图
    完整性约束
    ASP.NET MVC学习笔记(二)登陆验证
  • 原文地址:https://www.cnblogs.com/lxhbky/p/15224224.html
Copyright © 2011-2022 走看看