Back to Blog
Grep options exclude6/17/2023 ![]() To exclude a directory that you specified, use the –exclude-dir with -R or -r option. For example, I want to exclude the word function that appears at the beginning of a line $ grep -v '^function' fn.txtīecause the word function appears at the ending of the line, it won’ be excluded. If you only want to exclude words that show at the beginning of a line. If you want to specify multiple strings at once, let’s use the -e option.įor example, I want to exclude limit and abcd string: $ grep -v -e limit -e abcd fn.txt ![]() ![]() ![]() If the string that you wanna search contains space, you must use parentheses or quotes.įor example, I want to exclude the line that contains string ab cd: $ grep -v 'ab cd' fn.txt Now I have a file named fn.txt.that contains the following contents:įor example, I want to exclude the line that contains the word function: $ grep -v function fn.txtĪs you can see, the line that contains the word function is filtered out. To display lines that don’t match the search pattern, let’s use the -v option. And it is also very important to exclude words and patterns or dictionaries and files.īelow is the guide on how to exclude in grep as we go through below. The grep command is used to filter out input files that match a regular expression then print to standard output. Grep stands for “global regular expression print” and it is a useful command in Linux.
0 Comments
Read More
Leave a Reply. |