Re: replace multiple string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



madunix@xxxxxxxxx wrote:
> pons
>
> On Fri, Sep 23, 2011 at 9:08 PM,  <m.roth@xxxxxxxxx> wrote:
>> madunix@xxxxxxxxx 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@xxxxxxxxx> wrote:
>>>> madunix@xxxxxxxxx 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@xxxxxxxxxx
>>>> http://lists.centos.org/mailman/listinfo/centos
>>>>
>>> _______________________________________________
>>> CentOS mailing list
>>> CentOS@xxxxxxxxxx
>>> http://lists.centos.org/mailman/listinfo/centos
>>>
>>
>>
>> _______________________________________________
>> CentOS mailing list
>> CentOS@xxxxxxxxxx
>> http://lists.centos.org/mailman/listinfo/centos
>>
> _______________________________________________
> CentOS mailing list
> CentOS@xxxxxxxxxx
> http://lists.centos.org/mailman/listinfo/centos
>


_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos



[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux