FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 09-23-2011, 05:47 PM
"madunix@gmail.com"
 
Default replace multiple string

Hi


I would like to use a bash script that searches files and
subdirectories name in a directory /var/ww/html/web
for a specific string, and when it finds the search string, replaces
the string (old1) with new string (new1), and so on
old2 with new2 ....oldn with newn.



replace_string.sh
#!/bin/bash
for db in $(find /var/www/html/web -name * -exec)
do
sed -e "s/old1/new1/"
sed -e "s/old2/new2/"
...
sed -e "s/oldn/newn/" $db
done

Any recommendation..

Thanks
pons
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 05:51 PM
 
Default replace multiple string

madunix@gmail.com wrote:
>
> I would like to use a bash script that searches files and
> subdirectories name in a directory /var/ww/html/web
> for a specific string, and when it finds the search string, replaces
> the string (old1) with new string (new1), and so on
> old2 with new2 ....oldn with newn.
>
> replace_string.sh
> #!/bin/bash
> for db in $(find /var/www/html/web -name * -exec)
> do
> sed -e "s/old1/new1/"
> sed -e "s/old2/new2/"
> ...
> sed -e "s/oldn/newn/" $db
> done

Close. I think
find /var/www/html/web -type f -exec sed -i -e
"s/old1/new1/;s/old2/new2/;..." {} ;
would do it. The -i is to make the change inplace, editing the existing file.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 05:59 PM
"madunix@gmail.com"
 
Default replace multiple string

>>-type f ??
the string could be a name of file name or subdirectory name

Thanks
pons

On Fri, Sep 23, 2011 at 8:51 PM, <m.roth@5-cent.us> wrote:
> madunix@gmail.com wrote:
>>
>> I would like to use a bash script that searches files and
>> subdirectories name in a directory /var/ww/html/web
>> for a specific string, and when it finds the search string, replaces
>> the string (old1) with new string (new1), and so on
>> old2 with new2 ....oldn with newn.
>>
>> replace_string.sh
>> #!/bin/bash
>> for db in $(find /var/www/html/web -name * -exec)
>> do
>> * sed -e "s/old1/new1/"
>> * sed *-e "s/old2/new2/"
>> ...
>> * sed -e "s/oldn/newn/" $db
>> done
>
> Close. I think
> find /var/www/html/web -type f -exec sed -i -e
> "s/old1/new1/;s/old2/new2/;..." {} ;
> would do it. The -i is to make the change inplace, editing the existing file.
>
> * * * * mark
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 06:07 PM
 
Default replace multiple string

madunix@gmail.com wrote:
>>>-type f ??
> the string could be a name of file name or subdirectory name
>
No, it can't. You are *not* going to edit directory names this way, and
should not.

mark

> Thanks
> pons
>
> On Fri, Sep 23, 2011 at 8:51 PM, <m.roth@5-cent.us> wrote:
>> madunix@gmail.com wrote:
>>>
>>> I would like to use a bash script that searches files and
>>> subdirectories name in a directory /var/ww/html/web
>>> for a specific string, and when it finds the search string, replaces
>>> the string (old1) with new string (new1), and so on
>>> old2 with new2 ....oldn with newn.
>>>
>>> replace_string.sh
>>> #!/bin/bash
>>> for db in $(find /var/www/html/web -name * -exec)
>>> do
>>> * sed -e "s/old1/new1/"
>>> * sed *-e "s/old2/new2/"
>>> ...
>>> * sed -e "s/oldn/newn/" $db
>>> done
>>
>> Close. I think
>> find /var/www/html/web -type f -exec sed -i -e
>> "s/old1/new1/;s/old2/new2/;..." {} ;
>> would do it. The -i is to make the change inplace, editing the existing
>> file.
>>
>> * * * * mark
>>
>> _______________________________________________
>> CentOS mailing list
>> CentOS@centos.org
>> http://lists.centos.org/mailman/listinfo/centos
>>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 06:08 PM
 
Default replace multiple string

madunix@gmail.com wrote:
>>>-type f ??
> the string could be a name of file name or subdirectory name
>
I hate webmail. After I hit <send> and while it was thinking about going,
I realized another question: are you trying to rename files?

mark
> Thanks
> pons
>
> On Fri, Sep 23, 2011 at 8:51 PM, <m.roth@5-cent.us> wrote:
>> madunix@gmail.com wrote:
>>>
>>> I would like to use a bash script that searches files and
>>> subdirectories name in a directory /var/ww/html/web
>>> for a specific string, and when it finds the search string, replaces
>>> the string (old1) with new string (new1), and so on
>>> old2 with new2 ....oldn with newn.
>>>
>>> replace_string.sh
>>> #!/bin/bash
>>> for db in $(find /var/www/html/web -name * -exec)
>>> do
>>> * sed -e "s/old1/new1/"
>>> * sed *-e "s/old2/new2/"
>>> ...
>>> * sed -e "s/oldn/newn/" $db
>>> done
>>
>> Close. I think
>> find /var/www/html/web -type f -exec sed -i -e
>> "s/old1/new1/;s/old2/new2/;..." {} ;
>> would do it. The -i is to make the change inplace, editing the existing
>> file.
>>
>> * * * * mark
>>
>> _______________________________________________
>> CentOS mailing list
>> CentOS@centos.org
>> http://lists.centos.org/mailman/listinfo/centos
>>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 06:13 PM
"madunix@gmail.com"
 
Default replace multiple string

yes files and directories too ..

pons

On Fri, Sep 23, 2011 at 9:08 PM, <m.roth@5-cent.us> wrote:
> madunix@gmail.com wrote:
>>>>-type f ??
>> the string could be a name of file name or subdirectory name
>>
> I hate webmail. After I hit <send> and while it was thinking about going,
> I realized another question: are you trying to rename files?
>
> * * * * * * mark
>> Thanks
>> pons
>>
>> On Fri, Sep 23, 2011 at 8:51 PM, *<m.roth@5-cent.us> wrote:
>>> madunix@gmail.com wrote:
>>>>
>>>> I would like to use a bash script that searches files and
>>>> subdirectories name in a directory /var/ww/html/web
>>>> for a specific string, and when it finds the search string, replaces
>>>> the string (old1) with new string (new1), and so on
>>>> old2 with new2 ....oldn with newn.
>>>>
>>>> replace_string.sh
>>>> #!/bin/bash
>>>> for db in $(find /var/www/html/web -name * -exec)
>>>> do
>>>> * sed -e "s/old1/new1/"
>>>> * sed *-e "s/old2/new2/"
>>>> ...
>>>> * sed -e "s/oldn/newn/" $db
>>>> done
>>>
>>> Close. I think
>>> find /var/www/html/web -type f -exec sed -i -e
>>> "s/old1/new1/;s/old2/new2/;..." {} ;
>>> would do it. The -i is to make the change inplace, editing the existing
>>> file.
>>>
>>> * * * * mark
>>>
>>> _______________________________________________
>>> CentOS mailing list
>>> CentOS@centos.org
>>> http://lists.centos.org/mailman/listinfo/centos
>>>
>> _______________________________________________
>> CentOS mailing list
>> CentOS@centos.org
>> http://lists.centos.org/mailman/listinfo/centos
>>
>
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 06:21 PM
 
Default replace multiple string

madunix@gmail.com wrote:
> pons
>
> On Fri, Sep 23, 2011 at 9:08 PM, <m.roth@5-cent.us> wrote:
>> madunix@gmail.com wrote:
>>>>>-type f ??
>>> the string could be a name of file name or subdirectory name
<snip>
>> I realized another question: are you trying to rename files?
>>
> yes files and directories too ..
>
Then different commands - sed for the files, mv for the directories.

This begins to look like a perl script.

mark
>>>
>>> On Fri, Sep 23, 2011 at 8:51 PM, *<m.roth@5-cent.us> wrote:
>>>> madunix@gmail.com wrote:
>>>>>
>>>>> I would like to use a bash script that searches files and
>>>>> subdirectories name in a directory /var/ww/html/web
>>>>> for a specific string, and when it finds the search string, replaces
>>>>> the string (old1) with new string (new1), and so on
>>>>> old2 with new2 ....oldn with newn.
>>>>>
>>>>> replace_string.sh
>>>>> #!/bin/bash
>>>>> for db in $(find /var/www/html/web -name * -exec)
>>>>> do
>>>>> ?* sed -e "s/old1/new1/"
>>>>> ?* sed ?*-e "s/old2/new2/"
>>>>> ...
>>>>> ?* sed -e "s/oldn/newn/" $db
>>>>> done
>>>>
>>>> Close. I think
>>>> find /var/www/html/web -type f -exec sed -i -e
>>>> "s/old1/new1/;s/old2/new2/;..." {} ;
>>>> would do it. The -i is to make the change inplace, editing the
>>>> existing
>>>> file.
>>>>
>>>> ?* ?* ?* ?* mark
>>>>
>>>> _______________________________________________
>>>> CentOS mailing list
>>>> CentOS@centos.org
>>>> http://lists.centos.org/mailman/listinfo/centos
>>>>
>>> _______________________________________________
>>> CentOS mailing list
>>> CentOS@centos.org
>>> http://lists.centos.org/mailman/listinfo/centos
>>>
>>
>>
>> _______________________________________________
>> CentOS mailing list
>> CentOS@centos.org
>> http://lists.centos.org/mailman/listinfo/centos
>>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 08:10 PM
Les Mikesell
 
Default replace multiple string

On Fri, Sep 23, 2011 at 1:21 PM, <m.roth@5-cent.us> wrote:

>>> I realized another question: are you trying to rename files?
>>>
>> yes files and directories too ..
>>
> Then different commands - sed for the files, mv for the directories.
>
> This begins to look like a perl script.
>

Either way, it's probably a bad idea to have a script that renames
directories in mid-path while you are recursing the tree without
giving it some thought.

--
Les Mikesell
lesmikesell@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 08:15 PM
 
Default replace multiple string

Les Mikesell wrote:
> On Fri, Sep 23, 2011 at 1:21 PM, <m.roth@5-cent.us> wrote:
>
>>>> I realized another question: are you trying to rename files?
>>>>
>>> yes files and directories too ..
>>>
>> Then different commands - sed for the files, mv for the directories.
>>
>> This begins to look like a perl script.
>
> Either way, it's probably a bad idea to have a script that renames
> directories in mid-path while you are recursing the tree without
> giving it some thought.

Urk! Good catch, Les, I hadn't even *thought* of that.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 09-23-2011, 08:51 PM
"madunix@gmail.com"
 
Default replace multiple string

I am planning to have this in 2 stages first -type f then -type d

pons

On Fri, Sep 23, 2011 at 11:15 PM, <m.roth@5-cent.us> wrote:
> Les Mikesell wrote:
>> On Fri, Sep 23, 2011 at 1:21 PM, *<m.roth@5-cent.us> wrote:
>>
>>>>> I realized another question: are you trying to rename files?
>>>>>
>>>> yes files and directories too ..
>>>>
>>> Then different commands - sed for the files, mv for the directories.
>>>
>>> This begins to look like a perl script.
>>
>> Either way, it's probably a bad idea to have a script that renames
>> directories in mid-path while you are recursing the tree without
>> giving it some thought.
>
> Urk! Good catch, Les, I hadn't even *thought* of that.
>
> * * mark
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 04:38 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org