Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Exclamation Deleting text within a range with sed.


    My goal is to delete all text between to points and then insert a newline between these two points using sed stream editor (I should mentioned these commands will be executed from a sed script not directly on the command line).

    Example: delete text between two points.
    point A
    line 1 <-- Delete
    line2 <-- Delete
    point B

    results in:
    point A
    point B

    Then: insert newline between these points .
    point A
    point B

    I have been using the following code, although the text is successfully deleted between the two points when it comes to the next command the insertion of the newline fails to happen as sed seems to not be able to match the regex:

    # Removes unwanted text between to points in the file.
    /point A/,/point B/{
    /point A/b
    /point B/b

    # Inserts newline where text was removed from last command.
    /point A/a\

    Thanks in advance for any help, advice or pointers.

  2. #2
    Linux User
    Join Date
    Jan 2007
    here's a way, using the marker "nnnn" supposed never to occur at the
    beginning of a line:

    sed '/Point A/ a\nnnn' <filename |sed 's/^nnnn/ /'
    the sun is new every day (heraclitus)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts