Friday, May 3, 2024
16
rated 0 times [  16] [ 0]  / answers: 1 / hits: 52751  / 2 Years ago, sun, march 27, 2022, 11:02:13

I am new to using sed but I have been experimenting sed's s/..../..../ (substitute) to modify a full sentence if it's on one line but I am unaware an alternative solution on how to modify a sentence that may have been separated on two lines such as:



This:



Lorem Ipsum is simply dummy text of the printing and typesetting industry.


is actually written as this:



Lorem Ipsum is simply dummy text of the 
printing and typesetting industry.


How can you detect for this or code it to replace the entire sentence even if it's on two lines instead of one?


More From » command-line

 Answers
6

The following command will work in both situations:



sed '/Lorem.*/ {N; s/Lorem.*industry./string to replace/g}' filename


More explanations: How can I use sed to replace a multi-line string?


[#29372] Monday, March 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
truwom

Total Points: 101
Total Questions: 99
Total Answers: 100

Location: Ivory Coast
Member since Tue, Sep 15, 2020
4 Years ago
truwom questions
;