0
Q:

bash count the number of lines that meet condition

# Basic syntax:
awk 'condition { count_variable++ } END { print count_variable }' input_file
# Where:
#	- ++ increases the count by 1 when the condition is true
#	- END specifies what to do after the input_file has been processed

# Example usage:
awk '$3=="NA" { count++ } END { print count }' input_file
# This returns the count of the lines in column/field 3 that are NA

# Example usage:
awk '$1=="word" && $2==42 { count++ } END {print count}' input_file
# This returns the count of the lines that are "word" in column 1 AND
# 42 in column 2
1

New to Communities?

Join the community