Home > Software engineering >  Deleting the last four columns starting from specific row linux
Deleting the last four columns starting from specific row linux

Time:07-06

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

CodePudding user response:

If those are actual line numbers, then perhaps you just want:

awk 'NR>775{NF=22}1' input-file

If those numbers are not line numbers, but are data in the first column, then perhaps you want:

awk '$1>775{NF=22}1' input-file
  • Related