Chan Chen Coding...

          Use Sed in Multi-Files Text Processing

          During the software development, developers always need to modify multi code files since some bugs or requirement change. All of this modification may be similar, such as and insert the following code into JavaScript(<script> /*JavaScript Section*/</scripte>) section in JSP page, let us say we have A.jsp, B.jsp, and C.jsp. 
          function insertMe(){
              alert(“Hello”);
          }
          To complete this task, normally, we can open all three jsp file one by one, and copy + paste the function insertMe() into code. But if we have more files, it is boring and annoy to open echo file and insert the code.
          There is other smarter way to achieve this task, sed utility in Linux. In Linux, the sed provides the developer an convinces way. Just one command:
          sed –i ‘/<script>/ a\function insertMe(){\talert(“Hello”);\n}\n ‘ [ABC].jsp
          This script means: append function insertMe(){…} after <script> in A.jsp, B.jsp and C.jsp.
          Sed also provide other powerful feature, for more, please dive into ‘man sed’. Below is an example of replace.
          sed –e ‘s/Hello/Hello World‘ [ABC].jsp
          This script means replace all Hello with Hello World in A.jsp, B.jsp, and C.jsp.
          Because sed is a line oriented program.



          -----------------------------------------------------
          Silence, the way to avoid many problems;
          Smile, the way to solve many problems;

          posted on 2012-02-18 15:49 Chan Chen 閱讀(235) 評論(0)  編輯  收藏 所屬分類: Linux

          主站蜘蛛池模板: 兴城市| 巩留县| 汤阴县| 咸宁市| 晴隆县| 安达市| 常德市| 嘉义市| 商城县| 安仁县| 湟中县| 精河县| 深水埗区| 奉新县| 汤阴县| 勃利县| 芦溪县| 庄河市| 苏尼特右旗| 新乡市| 开化县| 瓦房店市| 铁力市| 利辛县| 平顺县| 江油市| 准格尔旗| 屏边| 高要市| 裕民县| 汕头市| 军事| 青田县| 广宗县| 茶陵县| 惠水县| 西宁市| 香港| 青岛市| 班玛县| 特克斯县|