linux - Script for counting lines in sections excluding # -


i'm searching ideas have script doing following:

i have textual file eg. test.txt similar text in it:

# # sectione 1 # several text lines  , on # # sectione 2 # more text , more # , more # ... # # sectione 3 # more more more  # # sectione 4 # ... ... 

i need possibility count lines in sectione 2 , exclude lines starting #

in above example script should show me counter "3" @ end eg.

# counter_script.sh test.txt  # 3 

is possibility , how can it? i'm using debian linux bash shell.

you can use following awk command:

awk '/sectione/{f=$3==2?1:0}f&&!/^#/{c++}end{print c}' file 

explanation in multiline version:

section2.awk:

/sectione/ {     # set f(ound) 1 (true) if number between 'sectione' 2     # otherwise 0 (false)     f=$3==2?1:0 }  # if f(ound) true (1) , line starts not # # count f&&!/^#/{     c++ }  # @ end of input print c(ount) end{     print c } 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -