The contents of the file testing.txt are:
ls -a cmake --verbose verbose
I want to use
grep to look through this file and find only the word beginning with "--" i.e. the word "--verbose"
However using the following patterns as an argument for
grep does not work:
$ cat testing.txt | grep -- Usage: grep [OPTION]... PATTERN [FILE]... Try 'grep --help' for more information. $ cat testing.txt | grep - ls -a cmake --verbose $ cat testing.txt | grep '--v' grep (GNU grep) 3.1 Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>. $ cat testing.txt | grep ver cmake --verbose verbose $ cat testing.txt | grep '-ver' ls -a
grepthinks that all arguments beginning with a
--are options? How do you prevent this so that grep can search for a pattern (in a file) that begins with "--"?
- the last attempt uses the pattern "-ver" so that
grepdoes not think the pattern is an option, but then
grepdoes not match the word "--verbose" in the file even though it contains the pattern "-ver". What causes this behavior?