Anna1364
Anna1364

Reputation: 154

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?

Upvotes: 0

Views: 45

Answers (1)

M--
M--

Reputation: 29119

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.

Upvotes: 1

Related Questions