我有两个很长的串联数组:
["MyHashMap"
"remove"
"put"
"remove"]
[[]
[27]
[65,65]
[19]]
我只是进入可视化模式,y
第二个数组,然后回到第一行,到它的末尾,添加空格并点击p
。它变成:
["MyHashMap"
[[]
[27]
[65,65]
[19]]
"remove"
"put"
"remove"]
我想要的输出是:
["MyHashMap" [[]
"remove" [27]
"put" [65,65]
"remove"] [19]]
我怎样才能做到这一点?
:set virtualedit=all
,这样您就可以将光标移动到没有字符的地方(超过行尾)。
将光标移动到第5行第一列,并使用CTRL-V
进入视觉块模式。选择最后四行的内容。按d
删除所选内容。
将光标移动到第一行,即第二列所在的位置。按p
粘贴
所以…返回到原始数据格式(为了完整性,我添加了一个额外的"行"):
数据如下:
$ cat yuck
["MyHashMap","remove","put","put"]
["MyMashNap","mover","gut","hut"]
[[],44],[95,30]]
下面是awk脚本:
$ cat a.f
BEGIN{
FS=","
}
{
for (f = 1; f <= NF; f++) { a[NR, f] = $f }
}
NF > nf { nf = NF }
END {
for (f = 1; f <= nf; f++) {
for (r = 1; r <= NR; r++) {
printf a[r, f] (r==NR ? RS : OFS)
}
}
}
和如何运行它:
$ awk -f a.f yuck | column -t
["MyHashMap" ["MyMashNap" [[]
"remove" "mover" 44]
"put" "gut" [95
"put"] "hut"] 30]]
使用视觉块选择:
如果你在第一行:
4j ............. jump to line five
Ctrl-v ......... start visual block
3j$ ............ select the end of the paragraph
dgg ............ delete and goes to the first line
A<Space> ....... add an extra space
<Esc>p ......... paste deleted block