Search code examples
unixtextspace

How to exclude columns from a data.frame and keep the spaces between columns?


I have a tab.table (like below) with million of rows and 340 columns

HanXRQChr00c0001    68062   N    N   N   N   A
HanXRQChr00c0001    68080   N    N   N   N   A
HanXRQChr00c0001    68285   N    N   N   N   A

I want to remove 28 columns. It is easy to do that, but in the output file I lose the space between my columns.

Is there any way to exclude these columns and still keep the space between them like above?


Solution

  • You can try different things. I include some of them below:

    awk -i inplace '{$0=gensub(/\s*\S+/,"",28)}1' file
    

    or

    sed -i -r 's/(\s+)?\S+//28' file
    

    or

    awk '{$28=""; print $0}' file
    

    or using cut as mentioned in the comments.