Counting lines in each block file

hello
im new here so i want to say hi everybody :slight_smile:

i have to write a script and im newbie :confused: i hope that in this forum are many ppl who knows subject :slight_smile:

i have hundrets folders. in each folder is a file name trace.txt. each trace.txt has a lot of tracert's results separates with "-----" it lookes like that :

tracert results
-----
tracert results
-----
tracert results
-----

i have to count lines in each block between "-----". by this i mean counting how many points are between machines. results should be writen into file call for example count.txt with one number per line. for example

10
10
10
11
13
14
10

does anyone have idea how to do this? i think i should use awk, but awk is hard to learn and im getting lost in this subject :confused: i was able to make a part of this script, but the most important part i cannot wrie. i made something like this :

#!/bin/bash
 
for node in /home/michale/results/results_10h/*
  do 
    if [ -f $node/trace.txt ]
    then
        MISSING PART :)
    else 
        echo " there is no file to analyze! "
  done

sorry for my english, im not using it every day.

Try tu put this in the place of MISSING PART :slight_smile:

while read LINE
do
    I=0
    LINE=""
    until [ "$LINE" = "-----" ]
    do
        (( I++ ))
        read LINE || break
    done
    echo $I
done < $node/trace.txt # > $outputfile # Remove first comment to output to a file
 awk 'NF{c++}/^--/{print --c;c=x}' infile > outfile

thank you very much for interesting !
it works great. i used danmero's solution.

Danmero, I remove NF from your code, and get same output.

 awk '{c++}/^--/{print --c;c=0}'  infile > outfile

So what's the purpose to put NF in there ?

Don't count empty lines/records (just for safety :wink: )

An alternative solution in Perl:

$
$ cat -n f4
     1  line 1
     2  line 2
     3
     4  line 3
     5  line 4
     6  ----------
     7  line 1
     8  line 2
     9  line 3
    10  ----------
    11  line 1
    12
    13
    14  line 2
    15  line 3
    16  ----------
    17
    18  line 1
    19  ----------
$
$ perl -lne 'if (/^--/){print $x; $x=0} elsif(/./){$x++}' f4
4
3
3
1
$

tyler_durden