Thursday, March 23, 2017

Bash: sed - part VII


Changing lines




You must specify the new line separately from the rest of the sed command.




# sed '3c\
> This is a changed line of text.' data6.txt


This is line number 1.
This is line number 2.
This is a changed line of text.
This is line number 4.


---------------------------------------
# sed '/number 3/c\
> This is a changed line of text.' data6.txt


This is line number 1.
This is line number 2.
This is a changed line of text.
This is line number 4.


---------------------------------------
Instead of changing both lines with text, the sed editor uses the single line of text to replace both lines.


# sed '2,3c\
> This is a new line of test.' data6.txt


This is line number 1.
This is a new line of test.
This is line number 4.

No comments:

Post a Comment