Delete specific lines from a text file
use the sed command line editor to delete lines that match specific criteria.
https://linuxhandbook.com/sed-command-basics/
you can use sed in shell scripts.
# remove the 7 th line :
sed -i '7d' filename
# Remove lines containing a string pattern
# delete all the lines that contain the word 'abcd' :
sed -i '/abcd/d' filename
## Remove all empty lines
sed -i '/^$/d' filename
-i option : enables the in-place editing.
By default, sed will only display the output. With -i option, sed modifies the actual file without showing it on the display.
Note pattern string search is case-sensitive
You may use a regex pattern instead of a regular string.
sed -i '/cryptsetup/d' ~/.bash_history
sed -i '/gpg/d' ~/.bash_history
sed -i '/sed/d' ~/.bash_history