Just looking for
cat file | grep "--"
Just looking for
cat file | grep "--"
I'm not clear on the question. Are you looking to match records containing a double hyphen?
Try:-
grep "\-\-" file
The problem could be just that the hyphen is a special character, so you need to use the backslash to define you string to use it as just some text.
I hope that this helps
Robin
Liverpool/Blackburn
UK
It worked. I tried without the quotes but obviously didn't apply. To show lines containing two hyphens and not more I use:
cat file | grep "\-\-" | grep -v "\-\-\-"
Excellent. Pleased to be of assistance.
Robin
See also Useless Use of Cat.
grep "\-\-" file | grep -v "\-\-\-"
Or you can do it all in one awk:
awk '/--/ && !/---/' file
Loved that one
<file awk '/--/ && !/---/'
-- itself is the solution. If you ever need to grep these kind of words/strings etc, use "--" to disable to treat them as a switch
$ cat f3
--
-i
-v
$
$ grep -- -i f3
-i
$ grep -- -v f3
-v
$ grep -- -- f3
--
This also applies to other commands.
e.g.
$ touch -t
touch: option requires an argument -- t
Try `touch --help' for more information.
$
$
$ touch -- -t
$
$ rm -t
rm: unknown option -- t
Try `rm ./-t' to remove the file `-t'.
Try `rm --help' for more information.
$
$
$ rm -- -t
$
Hope it helps.
or use grep with "-e"
grep -e "--"
You can also grep for characters grep would mistake for parameters by 'disguising' them inside [].
grep "[-][-]" file
You can use the same trick, changing how a regex looks without changing its meaning, to prevent grep from grepping itself inside a ps listing, by the way. Much cleaner than | grep -v grep.
ps | grep '[p]rocessname'
Or:
grep \\--
(only the first - needs escaping)