search and replace a specific text in text file?

I have a text file with following content (3 lines)

filename : output.txt

first line:12/12/2008
second line:12/12/2008
third line:Y

I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before.

I tried using cat output.txt |sed -e 's/third line:Y/third line:Y/' , but in this case it writes the output to some other file and we have to replace that old file with new file.

Do we have a way to do this without replacing the old file with new file after using sed command or can we do this any command other than sed?

sed -i 's/third line:Y/third line:N/' your-file

thanks

your sed does not support the inline edit -i option.

using Perl:

perl -pi -e 's/third line:Y/third line:N/' output.txt

Regarding only changing the third line:

$ cat f
yy
yy
yy
yy
yy
$ sed '3s/yy/nn/' f
yy
yy
nn
yy
yy

Does this help?