Question: Making a new header depending on entries from old header
gravatar for ellieuk
7 weeks ago by
ellieuk10 wrote:

For many this will be very basic, but for me it's driving me nuts!

I have a tab-delimited header: sampleA sampleB sampleC

Depending on the number of samples I have, I want to make a new header as such:

For 3 samples: sampleA sampleB sampleC output001 output002 output003

For 4 samples: sampleA sampleB sampleC sampleD output001 output002 output003 output004 and so on...

I can duplicate the initial header to get the correct number of columns: paste header header

However, I want new column names.. and that's where I'm stuck....

unix • 106 views
ADD COMMENTlink written 7 weeks ago by ellieuk10
gravatar for RamRS
7 weeks ago by
Baylor College of Medicine, Houston, TX
RamRS30k wrote:

Use awk and NF. You can use printf to pad 0s.


echo -e "sampleA\tsampleB\tsampleC" | awk -F"\t" -vOFS="\t" '{printf($0"\t"); for(i=1;i<NF;i++) printf("output%03d\t",i); printf("output%03d",i)}'
ADD COMMENTlink modified 7 weeks ago • written 7 weeks ago by RamRS30k
Please log in to add an answer.


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