Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize compound search by vi in linux

Shulou Source: shulou.com Published: 2022-06-01 05:16:19 09月30日 Update

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!

Tags: Search character string command word pattern file list two article line content more regular expression less code function semicolon variable Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information Xiaomi MySQL Shulou Technology