Replace text between 2 particular lines in a text file using sed

Porcupine

Similar questions have been asked but they are for Powershell.

I have a Markdown file like:

.
.
.
## See also

- [a](./A.md)
- [A Child](./AChild.md)
.
.
.
- [b](./B.md)
.
.
.
## Introduction
.
.
.

I wish to replace all occurrences of .md) with .html) between ## See also and ## Introduction :

.
.
.
## See also

- [a](./A.html)
- [A Child](./AChild.html)
.
.
.
- [b](./B.html)
.
.
.
## Introduction
.
.
.

I tried like this in Bash

orig="\.md)"; new="\.html)"; sed "s~$orig~$new~" t.md -i

But, this replaces everywhere in the file. But I wish that the replacement happens only between ## See also and ## Introduction

Could you please suggest changes? I am using awk and sed as I am little familiar with those. I also know a little Python, is it recommended to do such scripting in Python (if it is too complicated for sed or awk)?

karakfa
$ sed '/## See also/,/## Introduction/s/\.md/.html/g' file

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using sed in terminal to replace text in file

From Dev

Between double curly braces: replace particular text

From Dev

Using sed to find-and-replace in a text file using strings from another text file

From Dev

Find and replace text in a file between range of lines using sed

From Dev

Remove particular lines from a text file in R

From Dev

Read between lines in text file

From Dev

Using sed to replace text within a java properties file

From Dev

Using sed in a Jython script to replace a whole line with a variable in a text file

From Dev

multiple file text replace with sed

From Dev

Deleting portion of a text file and following lines using sed

From Dev

sed - replace multiple lines (a whole block of text)

From Dev

shell bash, cat file whilst using sed to replace text

From Dev

Using sed in terminal to replace text in file

From Dev

Replace text in file with SED

From Dev

How to replace particular text in the txt file?

From Dev

How to replace a text with ":" using sed

From Dev

deleting lines between rows in a text file using awk or sed

From Dev

Replace text in file with variable using sed

From Dev

replace text lines between two characters

From Dev

Extract text between two text lines using sed

From Dev

Replace 2 lines in a file using sed command

From Dev

Using sed in bash to replace lines in a xml file

From Dev

using grep for particular lines in text files

From Dev

Use sed or awk to replace text between column

From Dev

Sed to discover and replace text BETWEEN two patterns

From Dev

Replace odd lines in one text file with the corresponding odd lines in another text file using sed/awk/etc

From Dev

Replace lines in text file inside tar file with sed and regular expressions

From Dev

Copy particular text from one file to other using GREP or SED

From Dev

Replace multiple lines in text file

Related Related

  1. 1

    Using sed in terminal to replace text in file

  2. 2

    Between double curly braces: replace particular text

  3. 3

    Using sed to find-and-replace in a text file using strings from another text file

  4. 4

    Find and replace text in a file between range of lines using sed

  5. 5

    Remove particular lines from a text file in R

  6. 6

    Read between lines in text file

  7. 7

    Using sed to replace text within a java properties file

  8. 8

    Using sed in a Jython script to replace a whole line with a variable in a text file

  9. 9

    multiple file text replace with sed

  10. 10

    Deleting portion of a text file and following lines using sed

  11. 11

    sed - replace multiple lines (a whole block of text)

  12. 12

    shell bash, cat file whilst using sed to replace text

  13. 13

    Using sed in terminal to replace text in file

  14. 14

    Replace text in file with SED

  15. 15

    How to replace particular text in the txt file?

  16. 16

    How to replace a text with ":" using sed

  17. 17

    deleting lines between rows in a text file using awk or sed

  18. 18

    Replace text in file with variable using sed

  19. 19

    replace text lines between two characters

  20. 20

    Extract text between two text lines using sed

  21. 21

    Replace 2 lines in a file using sed command

  22. 22

    Using sed in bash to replace lines in a xml file

  23. 23

    using grep for particular lines in text files

  24. 24

    Use sed or awk to replace text between column

  25. 25

    Sed to discover and replace text BETWEEN two patterns

  26. 26

    Replace odd lines in one text file with the corresponding odd lines in another text file using sed/awk/etc

  27. 27

    Replace lines in text file inside tar file with sed and regular expressions

  28. 28

    Copy particular text from one file to other using GREP or SED

  29. 29

    Replace multiple lines in text file

HotTag

Archive