I need to add/insert a value "new content" on the secondlast line of the same file without deleting any of the lines or content of my file.
The condition is that the file content keeps changing and line numbers do not remain fixed.
Sample file:
library_path="usr/lib/1.0"
if test -n "/usr/local/lib64"; then
: ${PATH=${HOME}/lib:/usr/local/lib64}
else
: ${L_PATH=${HOME}/lib}
fi
if test -n "/usr/local/libs"; then
: ${PATH=${HOME}/lib:/usr/local/}
fi
##comment1
#comment2
##comment3
#comment4
if vals"${PATH}"; then
PATH="${L_PATH}"
else
PATH="${LD_PATH}:${Y_PATH}"
fi
export LD_PATH
I am trying the below command but its inserting the content on every line of the file:
sed -i 'x; s/.*/new content/;p;x; $d' myfile.txt
Any help appreciated !!