All Questions
17
questions
0
votes
1
answer
340
views
Remove options from command
My inputs are commands followed by an unrestricted number of single-letter options, e.g. command -abc. Neither the command nor the options take any arguments. My goal is to remove certain options.
...
2
votes
2
answers
2k
views
How to grep for a pattern that looks like an option? [duplicate]
m@m-VirtualBox:~$ man netstat | grep "-t"
grep: invalid option -- 't'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
I don't want to pass the -t option ...
0
votes
1
answer
1k
views
grep flag to NOT ignore case
I have a simple script to search patterns in my code sources, named prgrep
#!/usr/bin/bash
grep -irnI --exclude-dir={.git,obj} --exclude=tags --color=auto "$@"
(The fact that it is a script ...
1
vote
2
answers
259
views
Aliasing grep in find's -exec option
I have these aliases in my ~/.bashrc
alias grep='grep --color=auto -H'
alias fgrep='fgrep --color=auto -H'
alias egrep='egrep --color=auto -H'
but they have no effect when I run find ... -exec grep .....
-2
votes
2
answers
2k
views
Command du -xh / | grep -P "G\t" explained?
I came across the command
du -xh / | grep -P "G\t"
I am interested in the switch -P of grep and what does it do. Also, can anyone explain what the "G\t" part does?
Please do not ...
6
votes
2
answers
14k
views
What does grep -w do?
In here grep is used with the option -w. I did man grep and grep --help to try to find what the aforementioned option does. Neither output says anything about a -w option.
What does that option do? ...
0
votes
1
answer
123
views
How to search based on a $OPTARG that I provided in a file?
I am trying to make an executable file for search a specific text. I want to retrieve any line in my data file that include the value that I pass it.
So I create a data file called .addr_book and I ...
59
votes
1
answer
3k
views
What is the actual purpose of GNU grep's -X option and why is it undocumented?
By reading this question, I have discovered that GNU grep has a -X option which expects an argument. Strangely, it is mentioned neither in the man page nor in the info page.
Looking at the source ...
4
votes
2
answers
133
views
Bug or Feature? Grep accepts files as flags
I just ran into a weird scenario, and I'm not sure if this is a feature, and if not, what sort of security implications does it represent? Likely nothing for grep, but other directory-crawling ...
8
votes
5
answers
6k
views
grep getting confused by filenames with dashes
I'm having a problem where grep gets confused when the directory contains a file starting with dashes.
For example, I have a file named "------.js" . When I do something like grep somestring * I get ...
1
vote
3
answers
945
views
Why doesn't grep return what I expect when I use single quotes
I have a file with the below contents:
sh-4.2$ cat file1
example of multiple
pattern
this is an
example of multipole
sorry multiple
pattern matching
using grep
so the example is the
file itself
-...
14
votes
2
answers
9k
views
grepping for word starting with hyphen gives error: invalid option -- 't'
When I grep the man page of the find command for matches to type it returns a lot of search results that I don't want. Instead I want to use a command that returns only the search results for -type.
...
3
votes
4
answers
11k
views
Test if command accepts a specific option
What is the preferred way to test if a command takes an option? What are the caveats?
As a motivating example, at login my shell aliases grep to add several --exclude-dir options but this option is ...
5
votes
2
answers
888
views
How do you get fgrep to find the literal "--help"?
fgrep --help | fgrep "--help"
returns just the whole fgrep --help, how do I return just the lines that have the literal "--help" in them?
The quotes don't do anything, nor does \-\-help.
7
votes
1
answer
3k
views
Understanding grep --label=
I am looking for an explanation how grep --label=LABEL works: Maybe somebody can give me an example [or two] on what --label= is for.
I understand what grep and zgrep are supposed to do – the ...