Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Collation of commonly used replacement commands in linux vi

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "the arrangement of common replacement commands in linux vi". In daily operation, I believe that many people have doubts about the arrangement of common replacement commands in linux vi. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "sorting out common replacement commands in linux vi". Next, please follow the editor to study!

: s/vivian/sky/ replaces the current line with sky as the first vivian

: s/vivian/sky/g replaces all vivian in the current line to sky

The first vivian of each line from the beginning of line n to the last line of replacement is sky

All vivian in each line from the beginning of the nth line to the last line is sky

N is a number. If n is., it starts from the current line to the last line.

:% s/vivian/sky/ (equivalent to: g/vivian/s//sky/) replaces the first vivian of each line with sky

:% s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all vivian in each line with sky

You can use # as the delimiter, and the / that appears in the middle will not be the delimiter

: s#vivian/#sky/# replaces the current line with sky/ as the first vivian/

:% oradata/apras/ oradata/apras/ aprasqpr apras1 + (replace with +): / replace with /): / replace with / apras1 +: / apras1 +

* * *

1.:s/vivian/sky/ replaces the current line with sky as the first vivian

: s/vivian/sky/g replaces all vivian in the current line to sky

2.: the first vivian of each line from the beginning of line n to the last line is sky

All vivian in each line from the beginning of the nth line to the last line is sky

(n is a number, if n is., from the current line to the last line)

3.:% s/vivian/sky/ (equivalent to: g/vivian/s//sky/) replaces the first vivian of each line with sky

:% s/vivian/sky/g (equivalent to: g/vivian/s//sky/g) replaces all vivian in each line with sky

4. You can use # as the delimiter, and the / that appears in the middle will not be the delimiter

: s#vivian/#sky/# replaces the current line with sky/ as the first vivian/

5. Delete ^ M from text

Problem description: for line feeds, enter newline (0A0D) is used in window, and carriage return (0A) is used in linux. In this way, when you copy a file from window to unix, there will always be a ^ M. Please write a shell or c program to filter the newline character (0D) of windows files under unix.

Use the command: cat filename1 | tr-d "^ V ^ M" > newfile

Use the command: sed-e "s / ^ V ^ M / /" filename > outputfilename. It should be noted that in methods 1 and 2, ^ V and ^ M refer to Ctrl+V and Ctrl+M. You have to type it by hand, not paste it.

Processing in vi: first open the file using vi, then press the ESC key, and then enter the command:% s / ^ V ^ M / /.

:% s / ^ M $/ / g

If the above methods are useless, the correct solution is:

Tr-d "\ r"

< src >

Dest

Tr-d "\ 015" dest

Strings A > B

6. Other

You can use the: s command to replace a string. Specific uses include:

: s/str1/str2/ replaces the string str1 that first appears on the line with the string str2

S/str1/str2/g replaces all occurrences of the string str1 on the line with the string str2

:. $s/str1/str2/g replaces the string str1 that appears from the current line to the end of the body with the string str2

: 1 s/str1/str2/g $s/str1/str2/g replaces all the strings str1 that appear in the body with the string str1

G/str1/s//str2/g function is the same as above

From the above replacement command, you can see that g is placed at the end of the command to replace each occurrence of the search string; without g, it means only the search

The first occurrence of the string is replaced; g is placed at the beginning of the command to replace all lines in the body that contain the search string.

At this point, the study of "sorting out the commonly used replacement commands for linux vi" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report