Hello everybody,
I'm trying to count the number of consecutive lines in a text file which have two distinctive column field values. These lines may appear in several line blocks within the file, but I only want a single block to be counted.
This was my first approach to tackle the problem (I'm a beginner, so be gentle :D) ...
# find line in which pattern INT appears for the first time in file topology
NR_1st_int=$(awk -v var="$INT" '$0~var {print NR}' topology | sed '1 !d')
# print molecule number of field 5 in that line into MOL
MOL_int=$(awk -v line_int="$NR_1st_int" 'NR==line_int {print $5}' topology)
# count number of lines that INT and MOL appear IN THE FILE
NINT=$(awk -v var1="$INT" -v var2="$MOL_int" 'BEGIN { count=0 } { if (( $4 == var1 ) && ( $5 == var2 )) count++} END{print count}' topology)
The main problem is that this (bad) code does not restrict the number NINT to a single block of occurring lines, which I need.
I've tried working with some loops but I messed it up every time. Can you help me out?