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0 0 0 0 0 0 0
781 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
782 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
783 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
784 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
785 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
786 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
我想从第776行到末尾删除最后四个0,以便列号与上一行匹配。定界符是空格。我知道所有行,我可以使用,
cut -f 21-
但是如何将其用特定的行与Whitepace作为定界符进行?谢谢
Here is part of my data
759 L 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
760 Y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
761 H 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
762 T 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
763 T 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
764 D 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
765 R 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
766 F 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
767 W 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
768 A 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
769 N 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
770 C 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
771 L 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
772 G 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
773 Y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
774 S 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
775 H 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
776 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
777 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
778 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
779 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
780 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
781 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
782 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
783 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
784 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
785 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
786 X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I want to delete last four 0s starting from line 776 to the end so that the column number matches with the previous rows. The delimiters are whitespace. I know for all rows, I can use
cut -f 21-
but how to How can I make it with specific rows with whitespace as delimiter? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在任何Posix Awk中,都不更改其余字段之前或之后的任何间距:
In any POSIX awk, without changing any of the spacing before/after or between the remaining fields:
如果这些是实际的行号,那么也许您只想要:
如果这些数字不是行号,而是第一列中的数据,那么也许您想要:
If those are actual line numbers, then perhaps you just want:
If those numbers are not line numbers, but are data in the first column, then perhaps you want:
由于我不清楚的原因,如果我将双重空间崩溃并破坏了它的格式,我只能到达上半场
nf = 22
。如果您非常确保
nf
计数为22
和26
,然后将完美排列,然后只是做干净而简单 - 没有
REGEX
,没有功能调用,没有数组拆分,没有状态跟踪,没有c? t:f
保持原始格式完整:
nf
使用它看到的第一行:for reasons unclear to me, I can only get to
NF = 22
for first half if I collapse the double space in between and ruin the formatting of it.If you're very sure the
NF
counts are22
and26
, and will perfectly line up afterwards, then just doclean and simple — no
regex
, no function calls, no array splits, no state tracking, and noC ? T : F
To keep original formatting intact :
NF
using 1st row it sees :