Answers for "bash count the number of lines that meet condition"

1

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
Posted by: Guest on October-01-2020

Code answers related to "bash count the number of lines that meet condition"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language