linux 文本批量替换

[root@php-lb01 admin]# ll
total 64
-rw-r--r-- 1 root root  947 Feb 22 17:13 adminapi.conf
-rw-r--r-- 1 root root  930 Feb 22 17:13 adminlog.conf
-rw-r--r-- 1 root root  910 Feb 22 17:12 bfc.conf
-rw-r--r-- 1 root root  906 Feb 21 19:35 bi.conf
-rw-r--r-- 1 root root  910 Feb 22 17:12 crm.conf
-rw-r--r-- 1 root root  906 Feb 22 17:12 fi.conf
-rw-r--r-- 1 root root  910 Feb 21 19:35 gps.conf
-rw-r--r-- 1 root root  910 Feb 21 19:35 osm.conf
-rw-r--r-- 1 root root  917 Feb 21 19:35 pass.conf
-rw-r--r-- 1 root root 1661 Feb 21 19:35 pat.conf
-rw-r--r-- 1 root root  910 Feb 21 19:35 prm.conf
-rw-r--r-- 1 root root  910 Feb 21 19:35 psi.conf
-rw-r--r-- 1 root root  910 Feb 21 19:35 sfc.conf
-rw-r--r-- 1 root root  910 Feb 21 19:35 sta.conf
-rw-r--r-- 1 root root 1567 Feb 21 19:35 stf.conf
-rw-r--r-- 1 root root  912 Feb 22 17:31 stt.conf

[root@php-lb01 admin]# grep "server 10.1.8.17" ./*   # 查询当前目录下所以包含server的行及文件                     
./adminapi.conf:        #server 10.1.8.17:8701 max_fails=3 fail_timeout=30;
./adminlog.conf:        #server 10.1.8.17:8702 max_fails=3 fail_timeout=30;
./bfc.conf:     #server 10.1.8.17:8703 max_fails=3 fail_timeout=30;
./bi.conf:      #server 10.1.8.17:8704 max_fails=3 fail_timeout=30;
./crm.conf:     #server 10.1.8.17:8705 max_fails=3 fail_timeout=30;
./fi.conf:      #server 10.1.8.17:8706 max_fails=3 fail_timeout=30;
./gps.conf:     #server 10.1.8.17:8716 max_fails=3 fail_timeout=30;
./osm.conf:     #server 10.1.8.17:8707 max_fails=3 fail_timeout=30;
./pass.conf:    #server 10.1.8.17:8709 max_fails=3 fail_timeout=30;
./pat.conf:     #server 10.1.8.17:8708 max_fails=3 fail_timeout=30;
./prm.conf:     #server 10.1.8.17:8710 max_fails=3 fail_timeout=30;
./psi.conf:     #server 10.1.8.17:8711 max_fails=3 fail_timeout=30;
./sfc.conf:     #server 10.1.8.17:8712 max_fails=3 fail_timeout=30;
./sta.conf:     #server 10.1.8.17:8714 max_fails=3 fail_timeout=30;
./stf.conf:     #server 10.1.8.17:8713 max_fails=3 fail_timeout=30;
./stt.conf:     #server 10.1.8.17:8715 max_fails=3 fail_timeout=30;

[root@php-lb01 admin]# grep "server 10.1.8.17" -rl ./*  # 查询当前目录下所以包含server的文件                     
./adminapi.conf
./adminlog.conf
./bfc.conf
./bi.conf
./crm.conf
./fi.conf
./gps.conf
./osm.conf
./pass.conf
./pat.conf
./prm.conf
./psi.conf
./sfc.conf
./sta.conf
./stf.conf
./stt.conf

# server 10.1.8.17  批量修改为 #server 10.1.8.17
[root@php-lb01 admin]# sed -i 's/server\ 10\.1\.8\.17/#server\ 10\.1\.8\.17/g' `grep "server 10.1.8.17" -rl ./`  

# 文本里的www批量替换成www30
[root@php-lb01 admin]# sed -i 's/www/www30/g' `grep "www" -rl ./`



# logs/..._access.log 批量修改为 logs/admin_access.log ...为任意3个字符
[root@php-lb01 admin]# sed -i 's#logs\/...\_access\.log#logs\/admin\_access\.log#g' `grep "access\.log" -rl stt.conf`  # 单个文件

[root@php-lb01 admin]# sed -i 's#logs\/...\_access\.log#logs\/admin\_access\.log#g' `grep "access\.log" -rl ./`        # 所以文件

 

posted @ 2017-02-22 19:34  sunmmi  阅读(166)  评论(0)    收藏  举报