I used the following command in the bash to remove the last two lines of bash.bashrc (I added some bad lines) : sed '69,70d' /etc/bash.bashrc
But it doesn't delete the lines permanently as I would like.
I used the following command in the bash to remove the last two lines of bash.bashrc (I added some bad lines) : sed '69,70d' /etc/bash.bashrc
But it doesn't delete the lines permanently as I would like.
This should work to remove the last two lines:
sed -n -e :a -e '1,2!{P;N;D;};N;ba' /etc/bash.bashrc
And then if you pipe it through | cat > /etc/bash.bashrc
it will overwrite the file with the new shortened content:
sed -n -e :a -e '1,2!{P;N;D;};N;ba' /etc/bash.bashrc | cat > /etc/bash.bashrc
One solution is using head -n -<n>
in combination of tee
.
Although head
does not support in place edit which is supported in sed -i
, you can accomplish in place edit using tee
command.
See: sed command find and replace in file and overwrite file doesn't work, it empties the file
head -n -2 /etc/bash.bashrc | sudo tee /etc/bash.bashrc >/dev/null