Process command line arguments in shell
Classified in : Homepage, Debian, Command line, To remember
When writing a wrapper script, one often has to process the command line arguments to transform them according to his needs, to change some arguments, to remove or insert some, or perhaps to reorder them.
grep --only-matching
Classified in : Homepage, Debian, Command line, To remember
grep is designed to print lines matching a given pattern, but I often need to print only the matching part, discarding the remaining.
I used to do that with sed, but it involves several actions: match, replace the line by only the matching pattern and print. Fortunately, GNU grep has an option to do just that:
-o
,--only-matching
- Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
Unfortunately it is not a standard option, so it may be missing on non-GNU systems.