How use echo with grep in a Unix shell script?

Eric Saboia

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
anishsane

grep -o | wc -l logic from other answer should work on most systems today.

Here is another mechanism using awk.

awk 'END{print RS " : " NR-1}' RS=Linux ~/workspace/ep-exercicios/m1/e2/intro-linux.html

Logic: split the file in records, with record separator = "Linux". In the end, print the record number.


e.g. for file containing these contents:

The Linux is a Unix-like and mostly POSIX-compliant computer operating system (OS) assembled under the model of free and open-source software development and distribution. The defining component of Linux is the Linux kernel, an operating system kernel first released on October 5, 1991 by Linus Torvalds. The Free Software Foundation uses the name GNU/Linux to describe the operating system, which has led to some controversy

records will be:

  1. The
  2. is a Unix-like and mostly POSIX-compliant computer operating system (OS) assembled under the model of free and open-source software development and distribution. The defining component of
  3. is the
  4. kernel, an operating system kernel first released on October 5, 1991 by Linus Torvalds. The Free Software Foundation uses the name GNU/
  5. to describe the operating system, which has led to some controversy

Occurrence count of Linux is 4 == last record number - 1.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to use for loop inside a echo statement in shell script

From Dev

How do I use the -ne flag for echo in a shell script?

From Dev

How to use negation of a command in a while loop with grep in shell script?

From Dev

Use variables with dot in unix shell script

From Dev

Use literal (*) in grep pattern within shell script

From Dev

Use literal (*) in grep pattern within shell script

From Dev

Grep / Find oracle table name from UNIX Shell / SQL Script

From Dev

Unix lynx in shell script to input data into website and grep result

From Dev

How to echo in shell script without executing the result

From Dev

how to clear % from echo -n in shell script

From Dev

How to use a Runtime variable in grep command in Unix

From Dev

How to invoke octave script in unix shell

From Dev

How to Pivot the data by awk in unix shell script?

From Dev

How to replace string in unix shell script

From Dev

How to invoke octave script in unix shell

From Dev

How to remove frontend spaces | Unix shell script |

From Dev

How to use echo in shell command from Makefile?

From Dev

How to find this pattern with grep in a shell script?

From Dev

PHP shell script 'echo -ne' how? (Shell Progressbar)

From Dev

A Unix shell command alternative to echo

From Dev

Issue with echo in shell script

From Dev

How to use SED or AWK instead of GREP as it is taking lot of time in shell script

From Dev

Is it possible to echo into a file, but use indenting in the shell script source?

From Dev

How to use getopts with unix shell functions?

From Dev

How to use regex in grep shell command

From Dev

How to use grep in shell with -e option set

From Dev

Shell UNIX : grep wild card

From Dev

Shell UNIX : grep wild card

From Dev

UNIX shell scripting if and grep command

Related Related

  1. 1

    how to use for loop inside a echo statement in shell script

  2. 2

    How do I use the -ne flag for echo in a shell script?

  3. 3

    How to use negation of a command in a while loop with grep in shell script?

  4. 4

    Use variables with dot in unix shell script

  5. 5

    Use literal (*) in grep pattern within shell script

  6. 6

    Use literal (*) in grep pattern within shell script

  7. 7

    Grep / Find oracle table name from UNIX Shell / SQL Script

  8. 8

    Unix lynx in shell script to input data into website and grep result

  9. 9

    How to echo in shell script without executing the result

  10. 10

    how to clear % from echo -n in shell script

  11. 11

    How to use a Runtime variable in grep command in Unix

  12. 12

    How to invoke octave script in unix shell

  13. 13

    How to Pivot the data by awk in unix shell script?

  14. 14

    How to replace string in unix shell script

  15. 15

    How to invoke octave script in unix shell

  16. 16

    How to remove frontend spaces | Unix shell script |

  17. 17

    How to use echo in shell command from Makefile?

  18. 18

    How to find this pattern with grep in a shell script?

  19. 19

    PHP shell script 'echo -ne' how? (Shell Progressbar)

  20. 20

    A Unix shell command alternative to echo

  21. 21

    Issue with echo in shell script

  22. 22

    How to use SED or AWK instead of GREP as it is taking lot of time in shell script

  23. 23

    Is it possible to echo into a file, but use indenting in the shell script source?

  24. 24

    How to use getopts with unix shell functions?

  25. 25

    How to use regex in grep shell command

  26. 26

    How to use grep in shell with -e option set

  27. 27

    Shell UNIX : grep wild card

  28. 28

    Shell UNIX : grep wild card

  29. 29

    UNIX shell scripting if and grep command

HotTag

Archive