A
A
Anastasia Potemkina2020-12-02 01:37:38
linux
Anastasia Potemkina, 2020-12-02 01:37:38

What command can replace grep -A?

It is necessary to display the description of the --color key from man ls. The teacher said to use man ls | grep - - '- -color' . But then the description is not displayed. What can replace grep-A with?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2020-12-02
@saboteur_kiev

and why -A needs to be replaced? why not add?

B
brar, 2020-12-02
@brar

man ls | less +/color

V
Victor Taran, 2020-12-02
@shambler81

man ls | grep -A 1 "\-\-color\[=WHEN\]"
5fc789b056429952359616.png
-A 1- after 1 line after found
'\-\-color\[\=WHEN\]'- escape special characters
Now you can either cut off show 1 line from the end or
man ls | grep -A 1 "\-\-color\[=WHEN\]" | tail -n1
tail - n1

man ls | grep -A 1 "\-\-color\[=WHEN\]" | grep -v =WHEN

-v negation
But if the task is more serious, for example, the description can be more than one line of two or a fixed number, then you need to do it differently grep here, not the awk helper, everything is yours because it supports both regular expressions and multiline and conditions;)
as an option, you can find out in mana where the ls mana file is located and parse data from it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question