I have a file abc.txt like below:
#%PAM-1.0
# Test file
# Hello World
#
# echo "Test"
/etc/init.d/xrdp start
# Comment again
echo "Hello again"
I wanted to insert a line as a first executable line after comments...So if I want to add a line echo "Batman"
after all the lines start with #, how can I achieve that?
The output should look like below:
#%PAM-1.0
# Test file
# Hello World
#
# echo "Test"
echo "Hello Batman"
/etc/init.d/xrdp start
# Comment again
echo "Hello again"
Please note that the line will not be added after other comment line # Comment Again
I tried below but it doesn't work. I am very new to Bash scripting so need help from the experts here.
sed -i '#/a "echo "Batman"' abc.txt
Thanks for your help!