Home > Software design >  How do I use "match a single character not present in the set" correctly in sed in linux b
How do I use "match a single character not present in the set" correctly in sed in linux b

Time:11-08

Thanks to help from stackoverflow, I arrived at the command below. But "match a single character not present in the set" does not work as I expect. The first capture ([^"][^\n,]*)should stop at ", or "\n , but currently only stops at ",\n . What is my mistake and how can I fix it?

Solution can only be in sed on linux bash and ideally is as close to my current command as possible (to be easier for me to understand).

sed -En ':a;N;s/.*CAKE_FROSTING\(\n*?\s*?"([^"][^\n,]*)"[\n,]?\s*"?(([^"][^\n,]*)?")?.*,/\1\3/p;ba' filesToCheck/*

file.h

something else
CAKE_FROSTING(
   "is supreme "
"and best", 
"[i][agree]") something else
something more
something else

CAKE_FROSTING(
"is."kinda" neat " "in "fact"", 
 "[i][agree]") something else
something more

something else
CAKE_FROSTING("is supreme", "[i][agree]") something else
something more
something else

current output

is supreme and best 
is."kinda" neat " "in "fact" 
is supreme "[i][agree]") something else

desired output

is supreme and best 
is."kinda" neat " "in "fact" 
is supreme

CodePudding user response:

Using GNU sed

$ sed -En ':a;N;s/.*CAKE_FROSTING\(\n*?\s*?"([^"][^\n,]*)"[\n,]?\s*"?(([^"][^\n,]*)?")?.*,[^\n]*/\1\3/p;ba' input_file
is supreme and best
is."kinda" neat " "in "fact"
is supreme
  • Related