I want to take my file of sample names "sample_names.txt" and rename the samples based on another file "preg_stage.txt".
So my sample_names.txt file has a column of all my sample 1PL-BP, 2PL-BP... and my preg_stage file has the corresponding name (1PL-BP...) in the first column and the pregnancy stage (mid_preg, late_preg...) in the second column. I want to change all my sample names to the pregnancy stages using these two files. I am new to linux and need help!
This is file sample_names.txt
1PL-BP
2PL-BP
3PL-BP
....
This is the preg_stage.txt file:
sample preg_stage
1PL early_preg
2PL mid_preg
3PL late_preg
.....
@bark9299 , Welcome, give a small representative sample of your sample_names.txt and preg_stage.txt files along with the expect result of processing you expect. attempting to describe content is a waste of time, whereas showing (sample of) and expected results pretty much describes what is needed.
The forum is a COLLABORATION, we don't offhand write solutions without the requester (yourself in this instance) participating - ie, show your coded attempts, the team can then come back with suggestions (maybe including working solutions)
thanks.
I dont even know how to start so... and also it wont let me upload my files. I'm asking people that know much more about linux because everything I try does not work
@bark9299, copy/paste a few lines from each file into the dialog box you've been typing into. separate them using the markdown menu options .
show the expected (desired) result of process these files, I can guess, but you know exactly what you want .... so just supply it.
thks
What is your programming experience ?
NB: this task has nothing to do with linux per se, its merely an environment where work can be done.
This is file sample_names.txt
1PL-BP
2PL-BP
3PL-BP
....
This is the preg_stage.txt file:
sample preg_stage
1PL early_preg
2PL mid_preg
3PL late_preg
I want to take preg_stage.txt file and use it as a key to find the sample names (#PL) and change it to the pregnancy stage so:
sample_names.txt
1PL-BP
2PL-BP
3PL-BP
turn into
early_preg
mid_preg
late_preg
....
Not much added 
Perhaps you want
#!/bin/sh
awk 'NR==FNR {K[$1]=$2; next} ($1 in K) {$0=K[$1]} {print}' preg_stage.txt FS="-" sample_names.txt
As a commented multi-line
#!/bin/sh
awk '
# If processing the first file
NR==FNR {
# Store column2 in array K that is indexed by column1
K[$1]=$2
# Jump to next input cycle
next
}
# Processing the other file
# If column1 is found in K indexes
($1 in K) {
# Copy the value (column2 of first file) to the input line
$0=K[$1]
}
# Print the input line
{ print $0 }
' preg_stage.txt FS="-" sample_names.txt
# First file, changed FieldSeparator, second file
the command worked perfectly. Thank you so much for your help and sorry I didn't write the question correctly to begin with. I'm very new to this and just trying to learn. Thanks!!