Change a column name according to the file name
1
0
Entering edit mode
6 months ago
dpc ▴ 170

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".

thanks, dpc

bash • 159 views
1
Entering edit mode
6 months ago
Ram 32k

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.