3 Comments

  1. This was very helpful.
    Question.
    Once we have the offending line removed, how do we (using the command line) overwrite the file with the new, corrected version?

    For example…
    sed ‘//d’ file.txt
    removes the html expression but now I want to save this version to the same file.

    Thank you for any suggestions.

  2. Greetings. I found the answer. Insert -i after sed command.

    sed -i ‘//d’ file.txt
    overwrites the file with the corrected information.

    But

    What if the expression to remove contains a forward slash character. Haven’t figured out how to make this work.

    sed -i ‘//d’ file.txt

    There must be a way to escape the / character in the expression to remove. I’ve tried surrounding it with ‘ and \. Nether seem to be the solution.

    1. Hai we can delete a particular line in text file using sed command. But again how to recover that deleted text in that filename after deleting if by a mistake?

Leave a Reply

Your email address will not be published. Required fields are marked *