I need to use echo with grep in a shell script. Can I use it?
I tried this, but is incorrect:
echo Linux: grep "Linux" ~/workspace/ep-exercicios/m1/e2/intro-linux.html | wc -w
I need show the message:
Linux: (number of Linux word on the document).
Example:
Linux: 945
grep -o | wc -l
logic from other answer should work on most systems today.Here is another mechanism using
awk
.Logic: split the file in records, with record separator = "Linux". In the end, print the record number.
e.g. for file containing these contents:
records will be:
Occurrence count of Linux is 4 == last record number - 1.
Use
grep
with-o
option:should do it
grep manpage says :
Simply you can achieve it by doing slight modification below.
echo "Linux: `grep "Linux" ~/workspace/ep-exercicios/m1/e2/intro-linux.html | wc -w`"