zoukankan      html  css  js  c++  java
  • Linux_Best Practice_03_VIM_file comparation

    vi Searching and Replacing

    vi also has powerful search and replace capabilities. To search the text of an open file for a specific string (combination of characters or words), in the command mode type a colon (:), "s," forward slash (/) and the search string itself. What you type will appear on the bottom line of the display screen. Finally, press ENTER, and the matching area of the text will be highlighted, if it exists. If the matching string is on an area of text that is not currently displayed on the screen, the text will scroll to show that area.

    The formal syntax for searching is:

    :s/string

    For example, suppose you want to search some text for the string "cherry." Type the following and press ENTER:

    :s/cherry

    The first match for "cherry" in your text will then be highlighted. To see if there are additional occurrences of the same string in the text, type n, and the highlight will switch to the next match, if one exists.

    The syntax for replacing one string with another string in the current line is

    :s/pattern/replace/

    Here "pattern" represents the old string and "replace" represents the new string. For example, to replace each occurrence of the word "lemon" in a line with "orange," type:

    :s/lemon/orange/

    The syntax for replacing every occurrence of a string in the entire text is similar. The only difference is the addition of a "%" in front of the "s".with confirmation "gic":

    :%s/pattern/replace/gic

    Thus repeating the previous example for the entire text instead of just for a single line would be:

    :%s/lemon/orange

    compare two files:

    http://www.toontricks.com/2018/04/ubuntu-how-to-compare-two-files.html

    1. diff file1 file2

    2. sudo apt-get install meld

    3. vimdiff file1 file2

    4. diffuse file1 file2

    5. compare.py file1 file2

     1 #!/usr/bin/env 
     2 import sys  
     3 file1 = sys.argv[1]; file2 = sys.argv[2]; outfile = sys.argv[3]    
     4 def readfile(file):      
     5     with open(file) as compare:
     6           return [item.replace("
    ", "").split(" ") 
     7     for item in compare.readlines():
     8     data1 = readfile(file1); data2 = readfile(file2)  
     9     mismatch = [item[0] for item in data1 if not item in data2]    
    10     with open(outfile, "wt") as out:      
    11         for line in mismatch:
    12               out.write(line+" has changed"+"
    ")  

    6. cmp -b file1 file2

  • 相关阅读:
    css小技巧: select的css控制
    js中不存在exit函数,程序的运行中断停止,可使用return
    转载: WebCore渲染之一:基础
    转载: WEB架构师成长系列索引
    js:<form></form>中有<a>按钮时不能跳转?
    小心得:前台与后台的数据传递
    php session和cookie使用说明
    css 字体使用
    转载: PHP引用(&)使用详解
    三层架构下的增删改查 荣
  • 原文地址:https://www.cnblogs.com/tlfox2006/p/10053746.html
Copyright © 2011-2022 走看看