User Tools

Site Tools


awk:display_number_of_lines_that_contains_specific_string

AWK - Display number of lines that contains specific string

awk '/the_string/{n++}; END {print n+0}'  file.txt

Example

Assuming a file, test.txt, exists with the following contents:

10   Peter     Terence   Roux        45
11   Virginia  Genevieve  Roux        45
12   Felix     Devon     Roux         5
13   David     Bruce     Stevenson   48
14   Bob       James     Smith       16
48   Adam      Winter    Ridley      23

Running

awk '/Roux/{n++}; END {print n+0}'  test.txt

returns:

3
awk/display_number_of_lines_that_contains_specific_string.txt · Last modified: 2021/01/06 17:14 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki