All Questions
11
questions
807
votes
13
answers
1.8m
views
How do I grep for multiple patterns with pattern having a pipe character?
I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing
grep (foo|bar) *.txt
but the shell interprets the | as a pipe and ...
5
votes
2
answers
6k
views
Use of quotes in GNU grep regular expressions
I could see that certain patterns in the GNU Grep can be enclosed within brackets and certain others need not be. For example, matching the beginning of a word works only if it is enclosed within ...
57
votes
2
answers
114k
views
grep and escaping a dollar sign
I want to know which files have the string $Id$.
grep \$Id\$ my_dir/mylist_of_files
returns 0 occurrences.
I discovered that I have to use
grep \$Id$ my_dir/mylist_of_files
Then I see that the $...
4
votes
4
answers
2k
views
How can I grep for a string containing regex metacharacters like $ and '?
I want to search all files in the current directory and below for the substring $form['#node']. So, I have tried, initially:
grep -R "\$form\[\\\\'" . and grep -R "\$form\[\'" .
But it returns no ...
3
votes
2
answers
1k
views
Why does "grep '.*[s]' file" work and "grep .*[s] file" doesn't?
Comparing
grep '.*[s]' file
with
grep .*[s] file
Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
17
votes
2
answers
24k
views
Why do I have to escape a "dot" twice?
I know that we can escape a special character like *(){}$ with \ so as to be considered literals.
For example \* or \$
But in case of . I have to do it twice, like \\. otherwise it is considered ...
10
votes
2
answers
1k
views
What is the difference between "*.pl" and *.pl in grep? Why does quoting change the result?
What is the difference between:
grep "string" . -r --include *.pl
and
grep "string" . -r --include "*.pl"
The latter includes files in subdirectoried while the former not. Why?
8
votes
3
answers
33k
views
Escaping * with Regular Expressions and Grep
I have a file that has unique lines that start with 2 stars (**).
However when I run a grep command for
grep \*\* fileName
I get all of the lines in the file. This is very unusual, and what I see ...
5
votes
1
answer
7k
views
command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory
I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
2
votes
1
answer
950
views
grep misreads pattern from variable
I have a problem with escaped pattern put in grep.
My test file is:
export_cc = ${dir}/aaa/bbb/ccc
export_cc = ${dir}/aaa/bbb/eee
export_cc = ${dir}/aaa/bbb/ddd
export_cc = ${dir}/aaa/bbb/fff
...
1
vote
1
answer
1k
views
How to grep including single quote in a file
I have this line from file.php:
'user' => '',
What would be the appropriate command using grep to query the exact line?