z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Special search characters

z/OS UNIX System Services User's Guide
SA23-2279-00

In order to make searching more useful, vi gives special meanings to several characters when they are used in patterns. For example, the circumflex or caret character (^) stands for the beginning of a line. Move the cursor to the next line and type:
/^All
vi will look for the word All occurring at the beginning of a line.
The end of a line is represented by the dollar sign ($). Move the cursor to the next line and type:
/plum$
You will see that vi searches forward for a line that ends in the word plum.
Inside patterns, the dot (.) stands for any character. For example, move the cursor to the top of the file and type:
/t.e
You will see that the cursor moves to the word the. Type / over and over, and you will see the cursor keep jumping forward to any sequence of three letters that starts with t and ends in e. Were you surprised that the cursor jumped into the middle of the word slithey? vi finds character strings, even when they are in the middle of larger words.
Inside patterns, a dot followed by an asterisk (.*) stands for any sequence of zero or more characters. For example, type:
/^A.*g$
You will find the next line that begins with the letter A, ends with the letter g and has any number of characters in between.
Character
Stands for:
^
Beginning of the line
$
End of the line
.
Any character
.*
Any sequence of zero or more characters

vi gives special meanings to several other characters inside patterns. For complete details, see Appendix C. Regular Expressions (regexp) in z/OS UNIX System Services Command Reference. A regular expression is the POSIX name for a pattern; here we use the word pattern because it is more descriptive.

What happens if you want to search for a character that has a special meaning in patterns? For example, suppose you want to search for the string 2.3*25 somewhere in a file. If you just type:
/2.3*25
vi will think the 3* stands for zero or more occurrences of the digit 3, not the * character. In such cases, put a backslash (\) in front of any characters with special meanings, as in the example:
/2\.3\*25
Notice that we had to put a backslash in front of the dot as well as the asterisk; both have a special meaning in patterns.

By default, all searches in vi wrap around from the bottom of the file to the top. Similarly, if you use question marks to search backward through a file, the search will wrap around from the top of the file to the bottom, if necessary.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014