This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Change a column name according to the file name

I have around 52 files named like: ERR260147.genefamilies.tsv, ERR260158.genefamilies.tsv ERR275198.genefamilies.tsv, etc and each file has two columns. I want to change the second column name of each file according to the name of the file. For example, the second column name for file ERR260147.genefamilies.tsv will be named like ERR260147_Abundance-RPKs and for ERR275198.genefamilies.tsv will be ERR275198_Abundance-RPKs. Please note, part of a column name will come from the file name and a constant "_Abundance-RPKs".

Can anyone please help me.

thanks, dpc

bash

1 answer

Use awk. You'll need the variables NR, $2 and FILENAME and the function gsub. Google these and use them to assemble a mini-pipeline. This is a good learning exercise.

Log in to answer this question.