In the following file:
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut eu metus id lectus vestibulum ultrices. Maecenas rhoncus.
I want to delete everything before consectetuer
and everything after elit
.
My desired output:
consectetuer adipiscing elit.
How can I do this?
Best Answer
I'd use sed
Decoded the sed s/find/replace/ syntax:
s/^.*
-- substitute starting at the beginning of the line (^
) followed by anything (.*
) up to...\(
- start a named blockconsectetuer.*elit\.
- match the first word, everything (.*
) up to the last word (in this case, including the trailing (escaped)dot) you want to match\)
- end the named block.*
) to the end of the line ($
)/
- end the substitute find section\1
- replace with the name block between the\(
and the\)
above/
- end the replace