vi,sed,perl的正则表达式替换
VIM:
:1,5s/pattern/string/gi 1到5行
:%s/pattern/string/gi
sed:
sed -e s/pattern/string/gi originalfile > newfile #in FreeBSD: -E
perl:
#overwrite:
perl -pi -e ’s/bar/baz/’ fileA
perl -pi’*’ -e ’s/bar/baz/’ fileA
#backup to 'fileA.orig'
perl -pi’.orig’ -e ’s/bar/baz/’ fileA
perl -pi’*.orig’ -e ’s/bar/baz/’ fileA
#stdout
perl -pe ’s/bar/baz/’ fileA
:1,5s/pattern/string/gi 1到5行
:%s/pattern/string/gi
sed:
sed -e s/pattern/string/gi originalfile > newfile #in FreeBSD: -E
perl:
#overwrite:
perl -pi -e ’s/bar/baz/’ fileA
perl -pi’*’ -e ’s/bar/baz/’ fileA
#backup to 'fileA.orig'
perl -pi’.orig’ -e ’s/bar/baz/’ fileA
perl -pi’*.orig’ -e ’s/bar/baz/’ fileA
#stdout
perl -pe ’s/bar/baz/’ fileA
0 Comments:
Post a Comment
<< Home