Home > OS >  Consult the vi batch replacement
Consult the vi batch replacement

Time:11-08

Consult the vi batch replacement problem: I want to have & lt; Li> . In front of each group, plus & lt; Ul> , followed by & lt;/ul> Don't know this should be how to write!

CodePudding user response:

Using sed to replace good sed 's/& lt; Li>/& lt; Ul>
  • /; S/& lt; \/li>/& lt; \/li> <\/ul>/'file. TXT, this just print, do not change the source file, plus - I choice is to modify the original file sed -i' s/& lt; Li>/& lt; Ul>
  • /; S/& lt; \/li>/& lt; \/li> <\/ul>/'file. TXT to
  • Replace & lt; Ul>
  • ; The & lt;/li> Replace & lt;/li>

    Or replace with the inside of the vi
    : % s/& lt; Li>/& lt; Ul>
  • /g
    : % s # & lt;/li> # & lt;/li> # g (avoid conflict and/ul slashes, use # space)

    Also a kind of solution is matching with & lt; Li> Line, the beginning of a line operator ^ replace & lt; Ul> And end-of-line character $replace & lt;/ul>
    Sed -i '/& lt; Li>/s/^ & lt; Ul>/'file. TXT
    Sed -i '/& lt; Li>/s/$/& lt; \/ul>/'file. TXT

    CodePudding user response:

    You use the
    vi or vim?Look at the following output point to what
     readlink - e $(which vi) 


    In addition to using replace function (vim yourself or sed or awk),
    Just for the beginning or end can also be like this:
     # in the replacement period of the first line of the 
    # command mode
    0
    # visual mode
    Ctrl + v
    # move to the replacement period of the last line of the
    J # many times
    # insert mode
    I
    # enter the characters want

      # to return to command mode
      ESC
      # etc. Moments later, the results

    In the add at the end, do the following changes to the
     0 - & gt; $
    I - & gt; A

    CodePudding user response:

    Is there a better way? Top up!!!!!
    • Related