For Programmers: Free Programming Magazines  


Home > Archive > AWK > April 2005 > Find/Replace Mulitple text files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Find/Replace Mulitple text files
david

2005-04-15, 3:55 am

Can someone help me with creating a script for the following
scenario...

search through multiple files with text:

-------------------------------------------------------
texttexttexttexttexttexttexttexttexttext
texttext
texttexttexttexttexttexttexttexttexttext
texttext
thedir="hello"
texttexttexttexttexttexttexttexttexttext
texttext
texttexttexttexttexttexttexttexttexttext
texttext
-------------------------------------------------------

find in each file the string: thedir="hello"
hold anything between the quotes in a buffer: hello
replace the string with a new string + buffer + string:
thedir="\hello\"

Thank you for any help.

Ed Morton

2005-04-15, 3:55 am



david wrote:

> Can someone help me with creating a script for the following
> scenario...
>
> search through multiple files with text:
>
> -------------------------------------------------------
> texttexttexttexttexttexttexttexttexttext
texttext
> texttexttexttexttexttexttexttexttexttext
texttext
> thedir="hello"
> texttexttexttexttexttexttexttexttexttext
texttext
> texttexttexttexttexttexttexttexttexttext
texttext
> -------------------------------------------------------
>
> find in each file the string: thedir="hello"
> hold anything between the quotes in a buffer: hello
> replace the string with a new string + buffer + string:
> thedir="\hello\"
>
> Thank you for any help.
>


gawk '{$0=gensub(/(thedir=\")([^"]*)(\")/,"\\1\\\\\\2\\\\\\3","g")}1' file

Regards,

Ed.
david

2005-04-15, 3:55 am

Thanks a lot, Ed!!!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com