I recently had trouble with some regex on the command-line, and
found that for matching a backslash, different numbers of
characters can be used. This number depends on the quoting used for
the regex (none, single quotes, double quotes).
I know through (my very limited) experience that you can't use the asterisk alone in a regex, but I still don't quite understand why. After all, it should match 'any or no characters'. To my mind, '*grep' should match:
grep
egrep
fgrep
While '.*grep' should match
egrep
fgrep
...but not 'grep' because it seems like we are insisting upon a character in front of 'grep' with that dot.
I've seen several instances where people are doing this:
grep [f]oobar
But I don't understand why that is preferable to
grep foobar
Dear all
My boss recomended me to update my script code like this.
Code:
PIDFile=`cat pid`
PIDMemory=`ps -ef | grep $PIDFile | grep -v grep`
if [ $?
Hi
Here is the problem ( Exercise 3-3, Using The Shell of The Unix Programming Environment, Kerninghan, Pike, 3rd edition ):
Predict what each of the following grep commands will do, and then verify your understanding.
Code:
grep \$
grep \\$
grep \\\$
grep '\$'
grep '\'$'
grep \\
grep \\\\
grep "\$"
grep '"$'
grep "$"
A file containing these command
Of these two ways of searching a file recursively in all the subdirectories, which is faster / better ?
find . -regex ".*/.*abc.*"
or
find . | grep ".*abc.*"
Hello,
I have a file that I want to be able to insert a new line before every instance of a regex.
Hi,
I must be overlooking something, but I don't understand why this doesn't work. I'm trying to grep on a date, excluding all the lines starting with a dash:
testfile:
Code:
#2013-12-31
2013-12-31
code:
Code:
grep '^[^#]2013-12-31' testfile
I'm expecting to see just the second line '2013-12-31' but I don't get any results.
grep -v is not an option btw.
I am trying to understand the difference between grep -e and grep -E.