bash - Use Grep (or any other cmd line tool) to count Lines that contain different pattern -
i experimenting openmp, , trying write small shell script count of number of lines each thread outputs. , spit out each count. started getting it, , starting having write loop either hard coded or parameterized upper bound, , grep -c reg_ex, tried use sed clean output first make greps job easier, not working like
example program out(script input) output stdout (i can pipe sort first): thread 0: output thread 0: output thread 2: output thread 3: output thread 0: output thread 1: output . . .
etc
all need is:
thread 0: #repeats thread 1: #repeats . . . thread n: #repeats
thanks in advance
just pipe output this:
grep -o "thread [0-9]*" | sort | uniq -c | awk '{print $2, $3 ":", $1}'
this first reduce each line part before colon (so every line given thread outputs identical), count how many lines each thread output, , rearrange output of uniq
match sample output.
Comments
Post a Comment