Issue
I would like to know how to extract the corresponding header for a value that matches a regex expression in bash. I have the following table as a tsv:
I would like to match only the values that are not "-" and print the header corresponding to it as in the following:
isoniazid (ahpC_p.Asp73His)
What would be a simple code for this in bash?
Solution
This awk
script would output what you need:
awk 'NR == 1 { split($0, T); next }
{ for (i=1;i<=NF;i++) {
if ($i != "-") {
printf "%s (%s)\n", T[i], $i }
}
}' your_file_name
Just replace your_file_name
with whatever TSV file you want to parse.
Answered By - David