Hi all,
I have a question about sed programming, actually a one-liner for which I cannot find a solution, right now. I need to delete a line matching a specific pattern only if it is the last line. In practice, I would put together the following:
Code:
#
# This deletes the last line of a file
#
sed -i \$d file
#
# This deletes any line matching the pattern
#
sed -i /pattern/d file
Real example: the last lines of the original file are
Code:
2011-03-24 12:00 2570.13
2011-03-25 12:00 2285.03
2011-03-26 12:00 2109.07
Th following code deletes the second line from the last:
Code:
date=20110325
sed -i /$(date -d "$date" +%Y-%m-%d)/d file
in this case I want to avoid the deletion, since the pattern is not in the last line. How can I accomplish this? Thank you.