regex - Problems with repetition and grouping -


i'm trying use repetition trim down input sed pattern i'm getting unexpected results.

the text parsing structured as:

   \s+\d+\s+\d+\s+\d+\s+\d+\[0-9a-za-z] ... 

i've tried using repetition reduce volume of input on 1 line , make command simpler read/debug:

   ^\s+((\d+\s+){4})([0-9a-za-z]).*$ 

when try use in sed substitution command, value of \2 equal last word \1. if change repetition 4 5 can alphanumeric pattern \2 appears in \1. need values in \1 else don't want muddle results or use work around removing last word form \1 output.

does have idea why happening or doing wrong?

(i know awk easiest way deal problem determined solve sed , improve understanding of regular expressions.)

sed 's/\(\([[:blank:]]\{1,\}[0-9]\{1,\}\)\{4\}\)\([0-9a-za-z]\)/[\1](\2){\3}/' yourfile #  \1  +---------------------------------------+  #  \2    +------------------------------+ #  \3                                           +-------------+ 

replacement variable count front order of open parenthesis, not count of in case of repetition


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -