Is there a command-line utility app which can locate a specific block of lines in a text file?

Posted by fred.bear on Ask Ubuntu See other posts from Ask Ubuntu or by fred.bear
Published on 2011-01-08T19:11:08Z Indexed on 2011/01/08 20:00 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

The text "search and replace" utility programs I've seen, seem to only search on a line-by-line basis...

Is there a command-line tool which can locate one block of lines (in a text file), and replace it with another block of lines.?

For example: Does the test file file contain this exact group of lines:

'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,  
And the mome raths outgrabe. 

'Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!'

I want this, so that I can replace multiple lines of text in a file and know I'm not overwriting the wrong lines.

I would never replace "The Jabberwocky" (Lewis Carroll), but it makes a novel example :)

© Ask Ubuntu or respective owner

Related posts about command-line

Related posts about search