Question: How to add column to table with awk
0
gravatar for linelr
3 months ago by
linelr10
Norwegian University of Life Sciences
linelr10 wrote:

Hi Biostars community

I have a file with positions of methylated cytosines , but I want to add a new column to this file with the position+1 value (as if it was a dinucleotide).

I have used awk to print our the new value, but I need to add this new column to my file.

My file looks like this

NC_001960.1 1067
NC_001960.1 1068
NC_001960.1 1069
NC_001960.1 1133

And I do this with awk: awk -v s=1 '{print $(NF)+s}' test Which gives me this output:

1068

1069

1070

1134

And I´d like to add this as the third column in the above file

NC_001960.1 1067 1068
NC_001960.1 1068 1069
NC_001960.1 1069 1070
NC_001960.1 1133 1134

Is it possible to do this with awk or with some other method?

bash shell unix awk bed-files • 209 views
ADD COMMENTlink modified 3 months ago by Shalu Jhanwar470 • written 3 months ago by linelr10
3
gravatar for rpolicastro
3 months ago by
rpolicastro2.1k
rpolicastro2.1k wrote:

You can just slightly modify your awk command.

awk -v s=1 '{print $0,$(NF)+s}' test

NC_001960.1 1067 1068
NC_001960.1 1068 1069
NC_001960.1 1069 1070
NC_001960.1 1133 1134
ADD COMMENTlink modified 3 months ago • written 3 months ago by rpolicastro2.1k

Allright, that was so easy I´m almost embarrassed :) thanks a bunch!

ADD REPLYlink written 3 months ago by linelr10
1

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one if they work.
Upvote|Bookmark|Accept

ADD REPLYlink written 3 months ago by genomax91k
2
gravatar for Shalu Jhanwar
3 months ago by
Shalu Jhanwar470
Switzerland
Shalu Jhanwar470 wrote:

Yes, it's possible to append a column in the using the code below:

awk -v s=1 '{print $0,$(NF)+s}' test

Where test file is

NC_001960.1 1067

NC_001960.1 1068

NC_001960.1 1069

NC_001960.1 1133

The output of the code is:

NC_001960.1 1067 1068

NC_001960.1 1068 1069

NC_001960.1 1069 1070

NC_001960.1 1133 1134

ADD COMMENTlink written 3 months ago by Shalu Jhanwar470

thank you for taking time answering me!

ADD REPLYlink written 3 months ago by linelr10
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1024 users visited in the last hour