sed的题目

sed 在行首行尾插入字符:

sed还没有仔细的研究过,只知道一些常见的re规则,抽时间学习一遍,希望能对工作有帮助吧。

this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file
this is the test file

#在vim的命令行模式中执行以下命令,使得在每行前加入字符 :
%s/^/HEAD &/
g HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file HEAD this is the test file
#在vim的命令行模式中执行以下命令,使得在每行后加入字符 :
%s/$/& END/
g HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END HEAD this is the test file END

 另外,再摘抄一点:

Unix/Linux的文本换行是\n

windows的文本换行是\n\r

这样,文本文件在不同的系统上显示就出现问题:

linux的文本在windows上,成了一整行;windows的文本在linux下每行结尾都带有^M。

消除方法:使用unix2dos和dos2unix。

vim下面解决^M问题,可以使用:%s/^M//g。这里的^M,是ctrl+v and ctrl+M

posted @ 2013-08-07 09:25  快活王怜花  阅读(105)  评论(0)    收藏  举报