Yes, I know how to do that using perl, awk, python (...). I was just wondering if anyone knew about a dedicated command (that could have been part of any bioinformatic package...). Sorry for this misbioinformatic post.
Hello everybody,
Does anybody know a unix command to select columns from a tab delimited-file based on their respective names (something like "cut" but that would accept column names) ?
Thanks
1 answer
Assuming none of your columns has a space, the following awk one-liner should work to find SEARCHITEM:
awk 'NR==1{for(i=1;i<=NF;i++)if($i~/SEARCHITEM/)f[n++]=i}{for(i=0;i<;n;i++)printf"%s%s",i?" ":"",$f[i];print""}' /path/to/file/name
Google is your friend; I just searched awk column header match and followed the first result. A python/perl script would be a better choice, since this blows up if your column is missing or there are spaces in your first line.
No worries - we just don't want this forum to become a general programming resource, when those already exist. Like others have said - head over to stackoverflow, and you'll get great answers very quickly.
Log in to answer this question.
Hi. This question is not strictly related to bioinformatics, you should ask this question on stackoverflow.com
I'd move to close this on the grounds that it is not bioinformatics related, and as pointed out by David, awk is the answer.
Agree with Daniel, let's close it up.
I too agree as this is Bioinformatics group not stackoverflow