I'm trying to change the directory of all C headers like #include "library.h" to #include "prefix/library.h" in a file using the sed command, but I can't figure out how to add a prefix to the middle of a string. So far I've tried this command:
sed -i "s"\/'#include[[:space:]]*[<"][^>"]*[>"]'\/"$prefix"\/ $filename
but it replaces the whole string instead of creating #include "prefix/library.h". Is there any way to change it while keeping the original #include, <, " and spacing?
sedbackreferences; briefly,&lets you recall the entire matched string, and\1,\2etc backslash-parenthesized subexpressions from the match. You also seem to need a thorough refresher on the shell's quoting facilities.