Thursday 15 July 2010

regex - Regular expression to extract everything between braces in unix -


I am trying to extract everything from a text file between the braces and write the output in the other text file. I was able to create a regular expression to match everything between {} and it works fine (I wrote a simple Java program to test it), but I am not very strong in Unix so Unix is ​​not sure about using this regular expression. \ {([^}] +) \}

P> I have lowered the following command Tried,

  Cat Sample File | Sed -e s /.* \ {\ [[^}] + \) \}. * / / 1 / g '  

I'm getting the following error.

  sed: -e expression # 1, four 24: invalid predecessor regular expression   

between me to match everything between [] Regex got it and it works great is not sure where I'm going wrong Can anyone issue me my Rejox?

  cat file | Sed -e 's /.* \ [\ [[^]] * \) \].  >  cat file | Sed -e 's /.* {\ ([^}] \ + \)}. * / 1 / g '- & gt; Works    

You have to avoid + quantifier

No comments:

Post a Comment