This is much easier done with sed
than grep
. sed
can apply any of its one-letter commands to an inclusive range of lines; the general syntax for this is
START , STOP COMMAND
except without any spaces. START
and STOP
can each be a number (meaning "line number N", starting from 1); a dollar sign (meaning "the end of the file"), or a regexp enclosed in slashes, meaning "the first line that matches this regexp". (The exact rules are slightly more complicated; the GNU sed manual has more detail.)
So, you can do what you want like so:
sed -n -e '/http:\/\/www\.yahoo\.com/,$p' file1 > file2
The -n
means "don't print anything unless specifically told to", and the -e
directive means "from the first appearance of a line that matches the regexp /http:\/\/www\.yahoo\.com/
to the end of the file, p
rint."
This will include the line with http://www.yahoo.com/
on it in the output. If you want everything after that point but not that line itself, the easiest way to do that is to invert the operation:
sed -e '1,/http:\/\/www\.yahoo\.com/d' file1 > file2
which means "for line 1 through the first line matching the regexp /http:\/\/www\.yahoo\.com/
, d
elete the line" (and then, implicitly, print everything else; note that -n
is not used this time).