0

I have a large file that consists of many machine programs all together as one large txt file. I want to use sed to look for lines that start with an Oxxxx format like-

O00002 (A36 RETAINER ASSEMBLY .2495 HOLE OP 1) 
(RUN OPTIONAL STOP TO MOVE COOLANT) 

N2 (CD) 
T9 M06 
T3 
G00 G90 G54 G43 H09 Z5. X0. Y0. S2000 M03 
Z2. M08 

I have tried the following and many variations-

sed -i.gap '/^O[0-9]{4,5}.*/i testtest \n' ALL.NC

I have tried every example I've seen and nothing works. Any pointers towards syntax also appreciated.

Thank you!

  • What flavor or implementation of sed are you using? In a basic regular expression (BRE), the quantifier braces would need to be escaped, `[0-9]\{4,5\}` – steeldriver Jul 19 '22 at 23:18
  • I'm using gnu sed 4.8 and that fixed it! Mani have googled my ass off and read the f***ing manual (not close enough I suppose) and that's the first mention I've heard of that. – reTodd Ferreal Jul 19 '22 at 23:50
  • @steeldriver dude you did it again. Thank you very much! – reTodd Ferreal Jul 19 '22 at 23:51
  • `sed -E` enables "extended" regular expressions (like `grep -E`): `x{4,5}` is 4 or 5 x's and `x\{4,5\}` is the character sequence "x { 4 , 5 }" – glenn jackman Jul 20 '22 at 01:07
  • see also [Why does my regular expression work in X but not in Y?](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) – steeldriver Jul 20 '22 at 01:13
  • Thanks for the further reading! I'm having trouble figuring out how to something else now lol. I think I will start a thread just for this little project I'm working on. I kind of need it to work but mostly it's an excuse to get better with regex and sed/awk. Thank you guys very much! – reTodd Ferreal Jul 20 '22 at 09:09

0 Answers0