0

So I have this really long file in which there are lines that are built like this:

`somecode [ somecode > somecode ] somecode > somecode > somecode` 

I have to search for a string of atleast 9 + or - characters between the brackets and the same thing that was matched between those brackets have to be found between the two '>' next to the brackets... So far I came up with this;

`cat file | egrep -n '*\[.*([-+]{9,}).*\].*(>).*\1.*(>).*' > out.txt`
Pieterjan
  • 385
  • 5
  • 22
  • The code I use to grep doesn't work... Terminal keeps working on the job, but doesn't give any output – Pieterjan Nov 03 '12 at 20:51
  • @Pieterjan what kind of output do you want – Anirudha Nov 03 '12 at 20:54
  • Maybe, it's working really hard on your regexp, see http://www.regular-expressions.info/catastrophic.html for a possible explanation. – Olaf Dietsche Nov 03 '12 at 21:01
  • Could be, the file I need to search is over a 100 000 lines long... @Fake I want to have the full lines of where the regex are matched. Its just a string of 9 +'s between brackets, the same one has to be found between the >'s and the line has to be printed where it was found... – Pieterjan Nov 03 '12 at 21:11
  • Applying regex with backreferences on 100,000 lines is not a good idea - I would expect out of memory error, server halt or very long run... – Ωmega Nov 03 '12 at 23:23

1 Answers1

0

i guess from your regex,this is what you wanted to do

\[.*?([+-]{9,}).*?\].*?>.*?\1.*?>

if you want to get the full line use this

^.*?\[.*?([+-]{9,}).*?\].*?>.*?\1.*?>.*?$
Anirudha
  • 30,881
  • 7
  • 64
  • 81