Comments on: How to Delete a Line Containing Specific String using SED https://tecadmin.net/delete-a-line-containing-specific-string-using-sed/ How to guide for System Administrator's and Developers Thu, 24 Nov 2022 10:21:07 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: Jeremy Granger https://tecadmin.net/delete-a-line-containing-specific-string-using-sed/#comment-64022 Tue, 10 May 2022 19:18:03 +0000 https://tecadmin.net/?p=6910#comment-64022 It’s important to know how to do the redirection method because I work with older systems, like Solaris, and their version of sed is not so forgiving. I usually output (>) to a file like “file.tmp”, then “mv file.tmp file”

I would add that: sed -i.tmp ‘/^startswith/d’ /dir/file would be optimal. I end up needing to delete files but not using that I often have mixed results on different OS’s. I think with the more modern systems you may be able to get away with -i alone?

You can quote in ‘ or “. It would depend if you are want interpolation or not. Double quotes if you have a variable.

]]>
By: Rajesh Krishna Nandanwar https://tecadmin.net/delete-a-line-containing-specific-string-using-sed/#comment-62887 Sun, 16 May 2021 20:56:00 +0000 https://tecadmin.net/?p=6910#comment-62887 The syntax is incorrect. replace ‘ with ”

sed -i “/Text to Delete/d’” /path/to/file

]]>