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 閱讀(233) 評(píng)論(0)  編輯  收藏 所屬分類: Linux

          主站蜘蛛池模板: 阳泉市| 武隆县| 库车县| 商河县| 林芝县| 临汾市| 湟源县| 乌拉特中旗| 永修县| 体育| 雅安市| 长丰县| 金塔县| 松滋市| 阿尔山市| 五台县| 鄂州市| 呼图壁县| 巩义市| 沁水县| 陵川县| 武宁县| 荣昌县| 莫力| 财经| 镇坪县| 峨边| 石屏县| 雅安市| 江安县| 唐河县| 汕头市| 汕尾市| 盱眙县| 庐江县| 江城| 广元市| 乐东| 阳西县| 丰宁| 焦作市|