[Novalug] Command line search and replace tool - GNU sed?

James Ewing Cottrell III JECottrell3@Comcast.NET
Sat Sep 28 19:26:17 EDT 2013


What you also failed to notice is that there is a space after the hello.

Try: s/ *FOO */\nBAR\n/g

JIM

On 9/14/2013 10:25 PM, John Christopher wrote:
> I need a command line tool that will search and replace in a text file, and will *not* do regexp translations.
>
> GNU sed does *almost* what I want:
>
>      $ cat sedscript.txt
>      s/FOO/\nBAR\n/g
>
>      $ cat myfile.txt
>      hello FOO world
>
>      $ sed -f sedscript.txt     myfile.txt
>      hello
>      BAR
>       world
>
> In the example above, what I want is to have the following output:
>
>      $ sed -f sedscript.txt     myfile.txt
>      hello \nBAR\n world
>
> I want to avoid having to change \n to \\n in sedscript.txt (it gets difficult to read).
>
> Is there a way to instruct sed to *not* translate regexp metacharacters (such as \n) and leave it as is?
>
> Is there another command line tool that will do ultra-simple search and replace and *not* do regexp translations?
>
> Thanks for your help.
>
> _______________________________________________
> Novalug mailing list
> Novalug@calypso.tux.org
> http://calypso.tux.org/mailman/listinfo/novalug
>




More information about the Novalug mailing list