find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
速腾1994
论坛版主
帖子: 17379
注册时间: 2008-11-01 20:43
系统: Arch+gnome

find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

#1

帖子 速腾1994 » 2012-12-11 1:54

如题 :em03
头像
速腾1994
论坛版主
帖子: 17379
注册时间: 2008-11-01 20:43
系统: Arch+gnome

Re: find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

#2

帖子 速腾1994 » 2012-12-11 3:01

sed -i "s#1.1.1.1#2.2.2.2#g" /etc/hosts
头像
枫叶饭团
帖子: 14683
注册时间: 2010-06-16 1:05
系统: Mac OS X
来自: Tencent
联系:

Re: find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

#3

帖子 枫叶饭团 » 2012-12-11 9:11

??。。 。
onlylove
论坛版主
帖子: 5371
注册时间: 2007-01-14 16:23

Re: find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

#4

帖子 onlylove » 2012-12-11 9:15

自问自答?
去掉文件中的^M: sed -e "s/^M//g" filename > newfile
看这个帖子的时候坛子的小技巧……
#include <stdio.h>
void main()
{
double world;
unsigned letter;
short stay;
long memories;
printf("I miss you.\n");
}
头像
速腾1994
论坛版主
帖子: 17379
注册时间: 2008-11-01 20:43
系统: Arch+gnome

Re: find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

#5

帖子 速腾1994 » 2012-12-11 10:16

我以为是find 后来看到用sed'
因为我的手机里的hosts有些不适用我们这,所以我用nslookup 得到google的ip想替换掉
onlylove
论坛版主
帖子: 5371
注册时间: 2007-01-14 16:23

Re: find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

#6

帖子 onlylove » 2012-12-11 10:26

find不能替换吧,就是找到了也要调用其他程序替换
#include <stdio.h>
void main()
{
double world;
unsigned letter;
short stay;
long memories;
printf("I miss you.\n");
}
zhangxiaofir
帖子: 53
注册时间: 2010-12-09 23:54

Re: find /etc/hosts 里的1.1.1.1并全部替换为2.2.2.2

#7

帖子 zhangxiaofir » 2012-12-11 10:38

都好早哈 :em01
回复