# convert text file into c string sed -e 's/\\/\\\\/g;s/"/\\"/g;s/\t/\\t/g;s/^/"/;s/$/\\n"/' # something else... with explanation sed -n '/## Screensh/,/##/{/Scree/{p;n};/##/{q};p}' file -n -> not print '/## Screen/, /##/ -> match range, I guess you knew it already { -> if in this range /Scree/ -> and line matches /Screenshot/ {p;n}; -> do print line, and read next row (skip doing rest processing) /##/ -> if line matches "##" q; -> quit, we have done all printing p -> if we come to here, print the line }