Linuxvi search command

Source: Internet
Author: User
The divi search command divid & quot; article_content & quot; class & quot; article_content & quot; & gt; is often dizzy when you use the vi editor to edit long files, you cannot find the content you want to change. In this case, the search function is particularly important. The method is as follows: www.2cto. com1, command module... linux vi search command div id = "article_content" class = "article_content">
When using the vi editor to edit long files, they are often dizzy and cannot find the content to be changed. In this case, the search function is particularly important. The method is as follows: www.2cto.com 1. in command mode, enter "/string", for example, "/Section 3 ". 2. if you want to find the next one, press "n. To search up from the current cursor position, run the following command:/pattern Enter, where pattern indicates the specific character sequence to search. To search down from the current cursor position, run the following command :? After pressing Enter, vi searches for the specified pattern and positions the cursor at the first character of pattern.
For example, to search for the word "place", enter "www.2cto.com vi" to find and replace "vi/vim". you can use the "s" command to replace the string. In the past, only one format was used to replace the full text.
There are many ways to write (vi is really powerful, and there are still a lot to learn), record several types here for future query convenience.: S/vivian/sky/replace the first vivian in the current row with sky: s/vivian/sky/g, replace all vivian in the current row with sky: n, $ s/vivian/sky/replace the first vivian from row n to row n with sky: n, $ s/vivian/sky/g replace all vivian from row n to row n. If n is ., indicates starting from the current row to the last row: % s/vivian/sky/(equivalent to: g/vivian/s/sky/) replace the first vivian of each row with sky: % s/vivian/sky/g (equivalent to: g/vivian/s // sky/g) can be used as the separator to replace all vivian in each line with sky, in this case, the/in the middle will not be used as the separator: s # vivian/# sky/# replace the first vivian/in the current line Sky/: % s +/oradata/apras/+/user01/apras1 + (use + to replace/):/oradata/apras/with/user01/apras1/www.2cto.com 1.: s/vivian/sky/replace the first vivian of the current row with sky: s/vivian/sky/g, replace all vivian of the current row with sky 2.: n, $ s/vivian/sky/replace the first vivian from row n to row n as sky: n, $ s/vivian/sky/g replace all vivian from row n to row n with sky (n is a number, if n is ., indicates starting from the current row to the last row) 3.: % s/vivian/sky/(equivalent to: g/vivian/s // sky/) replace the first vivian of each row with sky: % s/vivian/sky/ G (equivalent to: g/vivian/s // sky/g), replace all vivian in each row with sky 4. you can use # as the separator. in this case, the/in the middle will not be used as the separator: s # vivian/# sky/# replace the first vivian/in the current line with sky/5. delete ^ M in text description: for line breaks, use Carriage Return to line breaks (0A0D) in Windows, and press enter (0A) in Linux. In this way, when you copy files on windows to Unix, there will always be a ^ M. please write a shell or c program that is used in unix to filter windows files (0D. Run the following command at www.2cto.com: cat filename1 | tr-d "^ V ^ M"> newfile; · run the following command: sed-e "s/^ V ^ M/" filename> outputfilename. Note that in methods 1 and 2, ^ V and ^ M indicate Ctrl + V and Ctrl + M. You must enter the file manually instead of pasting it. · Processing in vi: first open the file using vi, press ESC, and then enter the command: % s/^ V ^ M //. ·: % S/^ M $/g if the above method is useless, the correct solution is: · tr-d "\ r" <src> dest · tr-d "\ 015" dest · strings A> B 6. other use: the s command can be used to replace strings. The specific usage includes: s/str1/str2/replace str1 that appears for the first time in the line with string str2: s/str1/str2/g replace str1 www.2cto.com :., $ s/str1/str2/g replace str1: 1 with str2, $ s/str1/str2/g replace str1: g/str1/s // str2/g with string str2: g is placed at the end of the command to replace each appearance of the search string. without g, it means to replace the first appearance of the search string. g is placed at the beginning of the command, replaces all rows in the body that contain search strings. Author kisshua
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.