只保留一行的最后 10 个字符
Keep just the last 10 characters of a line
我有一个文件如下
!J INCé0001438823
#1 A LIFESAFER HOLDINGS, INC.é0001509607
#1 ARIZONA DISCOUNT PROPERTIES LLCé0001457512
#1 PAINTBALL CORPé0001433777
$ LLCé0001427189
$AVY, INC.é0001655250
& S MEDIA GROUP LLCé0001447162
我只想保留每行的最后10个字符,这样就变成了下面这样:-
0001438823
0001509607
0001457512
0001433777
0001427189
0001655250
我会将其视为 shell 脚本问题。在 vim 中输入以下内容:
:%! rev|cut -c1-10|rev
:%!
将通过以下过滤器管道整个缓冲区,然后过滤器直接来自 here。
:%s/.*\(.\{10\}\)/
: ex-commaned
% entire file
s/ substitute
.* anything (greedy)
. followed by any character
\{10\} exactly 10 of them
\( \) put them in a match group
/ replace with
said match group
对于单行,您可以使用:
hd0
$ go to end of line
9h go 9 characters left
d0 delete to beginning of line
假设 é
字符在一行中只出现一次,并且只出现在您的目标十位数之前,那么这似乎可行:
:% s/^.*é//
: command
% all lines
s/ / substitute (i.e., search-and-replace) the stuff between / and /
^ search from beginning of line,
. including any character (wildcard),
* any number of the preceding character,
é finding "é";
// replace with the stuff between / and / (i.e., nothing)
请注意,您可以使用 ctrl-k e'
键入 é
字符(control-k,然后是 e,然后是撇号,没有空格)。至少在我的系统上,这在插入模式和键入“替换”命令时有效。 (要查看可以使用 ctrl-k
“二合字母”功能调用的字符列表,请使用 :dig
或 :digraph
。
我有一个文件如下
!J INCé0001438823
#1 A LIFESAFER HOLDINGS, INC.é0001509607
#1 ARIZONA DISCOUNT PROPERTIES LLCé0001457512
#1 PAINTBALL CORPé0001433777
$ LLCé0001427189
$AVY, INC.é0001655250
& S MEDIA GROUP LLCé0001447162
我只想保留每行的最后10个字符,这样就变成了下面这样:-
0001438823
0001509607
0001457512
0001433777
0001427189
0001655250
我会将其视为 shell 脚本问题。在 vim 中输入以下内容:
:%! rev|cut -c1-10|rev
:%!
将通过以下过滤器管道整个缓冲区,然后过滤器直接来自 here。
:%s/.*\(.\{10\}\)/
: ex-commaned
% entire file
s/ substitute
.* anything (greedy)
. followed by any character
\{10\} exactly 10 of them
\( \) put them in a match group
/ replace with
said match group
对于单行,您可以使用:
hd0
$ go to end of line
9h go 9 characters left
d0 delete to beginning of line
假设 é
字符在一行中只出现一次,并且只出现在您的目标十位数之前,那么这似乎可行:
:% s/^.*é// : command % all lines s/ / substitute (i.e., search-and-replace) the stuff between / and / ^ search from beginning of line, . including any character (wildcard), * any number of the preceding character, é finding "é"; // replace with the stuff between / and / (i.e., nothing)
请注意,您可以使用 ctrl-k e'
键入 é
字符(control-k,然后是 e,然后是撇号,没有空格)。至少在我的系统上,这在插入模式和键入“替换”命令时有效。 (要查看可以使用 ctrl-k
“二合字母”功能调用的字符列表,请使用 :dig
或 :digraph
。