| If I understand your problem statement correctly, this should do ya':
| sed -n 's/.*\(keyword\)/\1/p'
$ cat infile
blah blah foo and stuff that follows "foo"
whatever bar baz foo and more stuff you want to print
yadda yadda foo yadda yadda yadda
foo is at the start of this line, as it happens
but the end of this line is foo
this line doesn't contain the magic word
$ sed -n 's/.*\(foo\)/\1/p' infile
foo"
foo and more stuff you want to print
foo yadda yadda yadda
foo is at the start of this line, as it happens
foo
$
A couple of things are apparent: (1) the command above may not produce
the desired output for an input line that happens to contain more than
one occurrence of the pattern to match (depending on what the desired
output is), and (2) since the pattern to match is invariable, there is
no need to tag it in the target string and backreference it in the
replacement string -- it might as well just be a literal string in both
cases. That is, this works just as well:
$ sed -n 's/.*foo/foo/p' infile
foo"
foo and more stuff you want to print
foo yadda yadda yadda
foo is at the start of this line, as it happens
foo
$
Given the first line of input above, how do you produce output that
consists of the first occurrence of "foo" and everything that follows
it? I honestly don't know how to do that with sed, although with some
other programs I use that support regular expressions, it would be
easy. For example, in one program I use, ".:*foo" would match the
shortest string of characters that were followed by "foo", as opposed
to ".*foo", which matches the longest such string. If I really want to
match the shortest such string, how do I match it with sed?
--