I need to look up the line number of a specific match in a file – email address – and then delete it from the beginning of the file until the matched line.
e.g Let's say the line number is 13807. So I need to keep the 13808+ lines intact.
Here's an example:
$ cat input
some
lines
before
mail@server.com
and
some
more
afterwards
$ cat output
and
some
more
afterwards
Best Answer
sed
Explanations
1,/mail@server\.com/d
–d
elete every line from line1
to (,
)mail@server.com
/mail@server\.com/,$!d
– don't (!
)d
elete every line frommail@server.com
to (,
) the end of the file ($
), but everything elseUsage
awk
Explanations
f
– variablef
, variables are0
=false
by default,awk
prints nothing if the expression isfalse
and just prints the line if the expression istrue
/mail@server\.com/{f=1}
– ifmail@server.com
is found setf=1
, therefore rendering the whole expressiontrue
the next timef
occurs in the expressionUsage