The Unix grep command is a search command built into a variety of Unix based operating systems. This command line utility, whose name stems from the original Unix term which means "search globally for lines matching the regular expression, and print them," can be accessed using the command line or terminal from anywhere in the Unix operating system. When given a particular list of files to search through, the Unix grep command becomes especially useful, as it can search through any amount of text to find exactly what you are looking for. The corresponding lines are then outputted to the computer screen for easy access.
The Unix grep command can be used in a variety of ways, from the most simplistic, usually only allowing for the location of the file and the term you are searching for, to highly complex, making use of a variety of operators and extra parameters.
Below is a basic Unix grep command:
grep Hello letter.txt
This command will search the file, "letter.txt," for all instances of the word "Hello." It is important to note that the word "hello" will not be printed to the screen because the grep command is inherently case sensitive. This feature can be disabled by including the flag "-i" before the word you are searching for, as in the example below:
grep -i Hello letter.txt
Using a command like this will display all instances of the word "Hello" no matter where any capitalizations occur.
Here is another example of a Unix grep command:
grep '^and' mydocument.txt
Placing a caret before a word will make the Unix grep command only search for that word if it appears at the beginning of a column of text. This means that the grep command will not find any words such as "candy" or "band," but will only find the word "and" as it appears by itself
How do I Use the Unix Grep Command?
tags: Linux | author: chaoPosts Relacionados:
Subscribe to:
Post Comments (Atom)
0 comment:
Post a Comment