sed regex not matching as expected -


I am trying to manipulate a yum repofile with SAL and the file is not working as expected. Looks like this:

  [repo id] name = value name = value [repo id] name = value name = value  

this is the best way But I still want to understand why this does not work ...

First I take a repo file and convert it to a big string:

  sed ': A; N; $! BA; S / \ n / ::: / g '$ repofile |  

Then, and this is the part that is not working , I want to match with a specific repo and trim the rest of the file. I am matching this opening [string in which there is the correct repo id. I want to match everything after this thing till the next opening [in the file:

  sed "s / ^ . * \ ([[$ {Repoid} \]. * \ [   

Then I put the new lines back and later change with awk .

  sed '/ ::: / \ n / g ~ ~ / trimed_repo> ~ / expanded_repo  

My problem is that my Regex is omitting the next opening [in the file and the files to be added with $ repo I tried to use the "lazy quantifier" but it prevented Ragex from matching exactly like this:

 < Code> sed "s /^.* \ (\ [$ {repoid} \]. *? \ [\]. * / / 1 /" & gt; ~ / trimed_repo  

And like this:

  sed "s /^.* \ (\ [$ {repoid} \] (. *?) \ [\]. * / \ 1 /" & gt ; ~ / Trimed_repo  

Answer *

So with some help in comments I did what works Is:

  sed "s /^.* \ (\ [$ {repoid} \] [^ [] * \) \ [. This is the lesson I should do - everything that is not an opening [unless you open it. [And which prevent unwanted behavior.  

Can someone explain why those options are different in those two examples? * This does not match in the example before the end of the file. Closes at the specified option but in the second incident it does not stop until the last event Bone.

I'm talking about the original, broken example:

  sed "s / ^. * \ (\ [$ {Repoid} \]. * \ [\]. * / / 1 / "& gt; ~ / trimed_repo  

  $ cat file [foo] [/ F = index ($ 0, "[" id "]")} f 'file [fu] name = 3 name = 17 $ awk -v id = "bar"' / \ [/ {f = index ( $ 0, "[" id "]")} f 'file [bar] name = 24 name = 5  

found only one flag set ( f above) When it finds a line containing [foo] , for example, and cleans it when it finds the next line containing [] This line prints when f is set.

Also note that unlike any possible solution solution, the above metro or RA metachactors or Delimiter characters will not be affected in search variables (e.g. .,?, *, +, /, (, Etc. etc.) because it is not searching for a regular expression on a STRING.

< / Div>

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -