Override last line in UNIX

Hello ,

I have to override the last line of a text file in unix
I know one way is to delete and insert however I am looking for a one liner.

Could anyone help me to write it?

below is the code I have come up with

sed '$d' /ParmFiles/test2_parm.dat>/ParmFiles/temp_pra.dat;
cat /ParmFiles/temp_pra.dat > /ParmFiles/test2_parm.dat;
echo '$$'"filename=`ls -lrt /SrcFiles/*_Matched*.csv| head -1 | nawk '{print $9}'`">> //ParmFiles/test2_parm.dat;
rm temp_pra.dat; 

However I am executing the code from different application and getting control M error so need a one liner

Hi,
You can try:

sed -e "\$s/.*/\$\$filename=`ls -lrt /SrcFiles/*_Matched*.csv| head -1 | nawk '{print $9}'`/" /ParmFiles/test2_parm.dat>/ParmFiles/temp_pra.dat

Regards.