Dear ALL,
I need some help with bash scripting, a script that search the content of multiple files and replace old string ip "10.5.1.10" with the new string ip "127.128.1.10" it will search in specific folder and sub folders
Thanks
On Tue, Sep 30, 2008 at 3:47 PM, Mad Unix madunix@gmail.com wrote:
Dear ALL,
I need some help with bash scripting, a script that search the content of multiple files and replace old string ip "10.5.1.10" with the new string ip "127.128.1.10" it will search in specific folder and sub folders
Thanks _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
sed -i 's/10.5.1.10/127.128.1.10/'
should help you example find /path/ <additional parameters to find the files> | xargs sed -i 's/ 10.5.1.10/127.128.1.10/'
Mad Unix wrote:
Dear ALL,
I need some help with bash scripting, a script that search the content of multiple files and replace old string ip "10.5.1.10" with the new string ip "127.128.1.10" it will search in specific folder and sub folders
Thanks _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
How about:
find <startdir> -exec sed "s/10.5.1.10/127.128.1.10/" {} ;
ChrisG
Except that you better quote the dots in the search string and put word boundary match around it or you'll end up replacing too much. See sed's -r switch for more.
On 10/1/08, Chris Geldenhuis chris.gelden@iafrica.com wrote:
Mad Unix wrote:
Dear ALL,
I need some help with bash scripting, a script that search the content of multiple files and replace old string ip "10.5.1.10" with the new string ip "127.128.1.10" it will search in specific folder and sub folders
Thanks _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
How about:
find <startdir> -exec sed "s/10.5.1.10/127.128.1.10/" {} ;
ChrisG _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On Tue, Sep 30, 2008 at 3:08 PM, Chris Geldenhuis chris.gelden@iafrica.com wrote:
How about:
find <startdir> -exec sed "s/10.5.1.10/127.128.1.10/" {} ;
First, the '' characters are unnecessary and confusing, except the one that precedes the semi-colon.
Second, that won't work. Sed does not perform on files in place - its output is sent to stdout unless it is redirected, and you can't redirect it back to the original file. To do something this way, you'd need a script that replaced the input file and used 'sed' to generate the new one (and then the script would have to rename it).
mhr
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
MHR wrote:
Second, that won't work. Sed does not perform on files in place - its output is sent to stdout unless it is redirected, and you can't redirect it back to the original file. To do something this way, you'd need a script that replaced the input file and used 'sed' to generate the new one (and then the script would have to rename it).
Au contraire:
- From the sed man page:
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
On Tue, Sep 30, 2008 at 4:12 PM, Barry L. Kline blkline@attglobal.net wrote:
Au contraire:
From the sed man page:
-i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if extension supplied)
Aha, bien sur, you are correct, M'sieur.
However, the original script as posted earlier in this thread did not include that little snippet, so that would be needed, in which case it could work.
Many thanks.
mhr
MHR wrote:
On Tue, Sep 30, 2008 at 3:08 PM, Chris Geldenhuis chris.gelden@iafrica.com wrote:
How about:
find <startdir> -exec sed "s/10.5.1.10/127.128.1.10/" {} ;
First, the '' characters are unnecessary and confusing, except the one that precedes the semi-colon.
Second, that won't work. Sed does not perform on files in place - its output is sent to stdout unless it is redirected, and you can't redirect it back to the original file. To do something this way, you'd need a script that replaced the input file and used 'sed' to generate the new one (and then the script would have to rename it).
mhr _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Apologies I should have included the -i switch for sed to modify file in place.
ChrisG
Thanks all
On 10/1/08, Chris Geldenhuis chris.gelden@iafrica.com wrote:
MHR wrote:
On Tue, Sep 30, 2008 at 3:08 PM, Chris Geldenhuis chris.gelden@iafrica.com wrote:
How about:
find <startdir> -exec sed "s/10.5.1.10/127.128.1.10/" {} ;
First, the '' characters are unnecessary and confusing, except the one that precedes the semi-colon.
Second, that won't work. Sed does not perform on files in place - its output is sent to stdout unless it is redirected, and you can't redirect it back to the original file. To do something this way, you'd need a script that replaced the input file and used 'sed' to generate the new one (and then the script would have to rename it).
mhr _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Apologies I should have included the -i switch for sed to modify file in place.
ChrisG
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
Mad Unix wrote:
Thanks all
if you are going to be posting to this list, I recommend you read up on what the general guidelists are. Eg. trim your posts atleast and dont top post.