awk - Substitutions with numbering on certain intervals -


i have simple sed command when applied standard output of type

\partie {méthode} {méthode}   \partie {méthode}  {méthode}   \partie {méthode} {méthode} {méthode}  \partie {méthode} 

... transforms

\partie {méthode 1} {méthode 2}   \partie {méthode 1}  {méthode 2}   \partie {méthode 1} {méthode 2} {méthode 3}  \partie {méthode 1} 

i understand awk allows insert numbers after each "méthode", how can put counter 1 after occurence of "\partie"?

awk solution:

awk -f'}' '/\partie/{ c=0 }/méthode/{ print $1,++c"}"; next }1' file 
  • -f'}' - optional/auxiliary field separator

  • /\partie/{ c=0 } - resetting counter on each \partie occurrence


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -