Below is a toy text file with sample and trait information, and a measurement.
Sample3_trait1 8.5
Sample6_trait2 2.2
Sample7_trait1 9.2
Sample3_trait2 1.3
Sample6_trait1 10.0
Sample7_trait2 2.1
I would like to replace the sample column with something more informative, like the actual name of the sample (say a persons name). This would be relatively easy in sed
if there were only 3 Samples, e.g.
sed 's/Sample3/john.D/g' file.txt
I could do this for each "sample". But i have 100s or thousands of sample names.
What id like to do is give sed
a text file with two columns, the original and the replacement:
Sample3 john.D
Sample6 mary.D
Sample7 kelly.O
....
Sample1001 amy.P
And have them replaced wherever they appear throughout the file (globally), i.e., whereever Sample3 is found, replace with john.D.
Is this something that I could do with a loop in Bash? I could loop over a single column (row by row), but Im not sure what to do with matched columns.
Any help would be much appreciated.