I have several files in a directory: file1.txt file2.txt file3.txt
For each file in the directory, I want to print only unique columns. Column 1 will match either 3 or 4; I want to print the columns that are unique and save it as f_parsed.txt
file1.txt:
gene1 description1 gene1 gene88
gene56 description2 gene67 gene56
gene6 description3 gene95 gene6
file1_parsed.txt:
gene1 description1 gene88
gene56 description2 gene67
gene6 description3 gene95
Here is the code that I have so far:
for f in *.txt ; do while IFS= read -r line; do awk -F "," '{if ($3 = $1) {print $1, $2, $3} else {print $1, $2, $4}}' > $f_parsed.txt;
done
Then, for each parsed file, I want to grep the gene in column 3 of f_parsed.txt and look for it in file_B.txt and return line with match and the following line. All lines with a match saved as match1.txt (next file will become match2.txt)
file_B.fasta looks like this:
>gene88 | shahid | ahifehhuh
TAGTCTTTCAAAAGA...
>gene6 | shahid | ahifehhuh
TAGTCTTTCAAAAGA...
>gene4 | jeiai | dhdhd
GTCAGTTTTTA...
>gene67 | vdiic | behej
GTCAGTTTTTA...
>gene95 | siis | ahifehhniniuh
TAGTCTTTCAAAAGA...
...
cat f_parsed.txt | while IFS= read -r line; do grep "$3" file_B.fasta |awk '{x=NR+1}(NR<=x){print}' > match1.txt ; done
My final output for the example file I began with should be called match1.txt and look like
>gene88 | shahid | ahifehhuh
TAGTCTTTCAAAAGA...
>gene67 | vdiic | behej
GTCAGTTTTTA...
>gene95 | siis | ahifehhniniuh
TAGTCTTTCAAAAGA...
Thanks in advance! I know the code is very rough, but I'm a beginner.