$ 0 0 With GNU sed. Print all lines, from the first to the line with the required string.sed '0,/foo/!d' file