分页: 1 / 1

求一正则

发表于 : 2010-01-25 10:32
yjcong
假设一文本里有很多 AMX, 有些AMX前面有the, 有些没有。 想把所有的AMX前面都加上the, 该如何弄呢?

thx

Re: 求一正则

发表于 : 2010-01-25 10:38
yuu1010
sed 's/the AMX/AMX/g' xxx.file> xxxx.file
sed 's/AMX/the AMX/g' xxxx.file
先删掉所有AMX前的the,再加上 :em06

Re: 求一正则

发表于 : 2010-01-25 11:07
yjcong
yuu1010 写了:sed 's/the AMX/AMX/g' xxx.file> xxxx.file
sed 's/AMX/the AMX/g' xxxx.file
先删掉所有AMX前的the,再加上 :em06
那其不是

less xxx.file|sed 's/the AMX/AMX/g'|sed 's/AMX/the AMX/g' >xxx.file
更方便

Re: 求一正则

发表于 : 2010-01-25 11:33
yingfei

代码: 全选

sed 's/\(the \)\?AMX/the AMX/g'  xxx.file > xxxx.file

Re: 求一正则

发表于 : 2010-01-28 0:37
tusooa

代码: 全选

s!(the\s+)?AMX!the AMX!g