【发布时间】:2020-04-13 03:53:04
【问题描述】:
Ubuntu 16.04
重击 4.4
我想删除第 n 行的最后 n 个字符。这是一个简单的文件,每行最后 4 个字符是数字 4。
root@0o0o0o0o0 ~/.ssh # cat remove.txt
00000000004444
55555555555555555555555554444
222222222222222224444
000033334444
111114444
要删除每行的最后 4 个字符,我可以执行 sed -i 's/....$//' remove.txt
root@0o0o0o0o0 ~/.ssh # sed -i 's/....$//' remove.txt
root@0o0o0o0o0 ~/.ssh # cat remove.txt
0000000000
5555555555555555555555555
22222222222222222
00003333
11111
但是,如果我想从第 4 行删除最后 4 个字符,删除 3,使文件看起来像这样:
0000000000
5555555555555555555555555
22222222222222222
0000
11111
【问题讨论】: