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

How to realize compound search by vi in linux

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you how to achieve compound search in linux vi, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Compound search

In vi, you can use the / command to search for a string, which requires specifying the pattern to match in the form of a literal string or regular expression. For example, to search for the word echo in a file, simply enter command mode, type / echo, and then press enter. This command will find the * * words on line 3 of the file shown in listing 6.

Listing 6. Compound search 1 #! / bin/ksh2 # 3 echo "Starting" 4 file=$ {1} 56 echo ${file} 78 if [[${file} = 1]]; then9 ((file=$ {file} + 1) 10 echo "Adding one gives"\ 11 ${file} 12 fi13 echo "Ending" 14 exit~~

You can use a simple regular expression to specify a line that contains a word followed by another word. For example, to find a * * line that contains the string echo, followed by zero or more characters, followed by the string file, you should use / echo.*file. In the file shown in listing 6, this command finds the * words on line 6.

However, this command is considered to match only if the two strings appear on the same line. If you want to search for a pattern or string that appears after another pattern or string, regardless of whether the two patterns or strings are on the same line, you can specify two search commands separated by a semicolon (;) to perform a compound search. For example, to search for the string echo that appears after the string {file} + 1, you should use / {file} + 1 match echo /. In the file shown in listing 6, this command finds the * words on line 10.

Compound search is particularly useful for finding a command in the code that appears after another command-for example, where a function is called after a variable is set.

The above is all the content of the article "how to implement compound search in vi in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report