Quote:
Originally Posted by coolloo_djack
hello!
I'm learning "grep" and "sed" command; So I don't no exactly what the command line below, does :
command line: grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
thank you for answering
|
grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
The bold part searches for "
Shell" in
/usr/share/doc/. However, /usr/share/doc/ specifies a directory, not a file, therefore grep will not return any result. You should do
grep Shell /usr/share/doc/some_file (assuming you're trying to search within a file).
grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
Pretending your first grep worked and returned "
README.", the bold part,
| sed '/README\./d', searches for "
README." in the grep return and deletes it. For example:
$ echo -e "README.\nREADME\nREADME."
README.
README
README.
$ echo -e "README.\nREADME\nREADME." | sed '/README\./d'
README
$
grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
The bold part searches the result AFTER the first grep and sed commands for "
README". Of which there is one in the result.
$ echo -e "README.\nREADME\nREADME."
README.
README
README.
$ echo -e "README.\nREADME\nREADME." | sed '/README\./d' | grep README
README
$
grep Shell /usr/share/doc/ | sed '/README\./d' | grep README | wc -l
The bold part then counts how many lines there are in after the first grep, sed, and second grep. The result would be one.
$ echo -e "README.\nREADME\nREADME." | sed '/README\./d' | grep README | wc -l
1
$