I have a file.txt and I have to delete the second-to-last line of the file. The below three sed commands are able to print the second-to-last line. But I need to delete that line. Any help??
sed -e '$!{h;d;}' -e x file.txt
sed -n 'x;$p' file.txt
sed 'x;$!d' file.txt
$ cat file.txt
apple
pears
banana
carrot
berry
Can we delete the second-to-last line of a file:
a. not based on any string/pattern.
b. based on a pattern - if second-to-last line contains "carrot"