[英]how to skip two lines and delete two lines till the end of file in vim?
我想跳过两行并删除两行,直到文件结尾
如果我的文件包含
111
222
333
444
555
666
777
888
999
1010
1111
我想将其修改为
111
222
555
666
999
1010
使用awk
awk 'NR%4==1 || NR%4==2' file
111
222
555
666
999
1010
NR%4==1
打印行1,5,9等
NR%4==2
打印第2,6,10行等
因此它给出了行1,2 5,6 9,19等
其他版本:
awk 'NR%4~/^[12]$/' #JS웃
awk '(NR-1)%4<2' #Ed Morton
使用sed
:
sed -n 'p;n;p;n;n' inputfile
对于您给定的输入,它将产生:
111
222
555
666
999
1010
使用GNU sed:
sed -n '1~4p;2~4p' inputfile
为了好玩,还可以使用perl
:
perl -ne 'print if grep($_==$.%4,(1,2))' inputfile
这可能对您有用(GNU sed):
sed 'n;n;$!N;d' file
仅Vim解决方案:
:%norm Jj2dd Aaaaa
然后
:%s/aaaa /\r/g
您需要手动拆分第一行(具有n),其余所有内容都就位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.