I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z).
I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in second column) by using the following.
But in this case inputfile1 is different , the keys are just not in single column but also in other columns.
Could you please help me on this.
Inputfile1
A tab F tab N
D
X tab Z
Inputfile2
A tab 1200
B tab 1000
D tab 3000
F tab AHAHA
G tab XXXXX
N tab YYYYY
X tab EEEEE
Z tab GGGG
I would like to join the the values or letters based on keys in 1st input file1
(A,F,N,D,X,Z) like the following
Output
A \t 1200 \t F \t AHAHA \t N \t YYYYY
D \t 3000
X \t EEEEE Z \t GGGG
Guys I have a Problem . Sorry for troubling.
I think you misunderstood me.
he output 1st row has to contain 3 keys as I mentioned (A, F and N)and their values
and 2nd row 1 key D and its value
3rd row ..............................................
while read line
do
s=""
for i in $line
do
s=$s"\t"$(grep -w $i input2.txt)
done
echo $s
done < input1.txt
Its working fine but not merging lines into a single line with tabs.like
others
while read line ; do
xline='^'$(echo "$line" | sed 's/\t/|^/g')
echo "$(echo "$(egrep "$xline" Inputfile2)"| tr '\n' '\t')" >> fileout.txt
done < Inputfile1
thanx in advance
and I'm using macbook (may be format of the file I have impoted from windows os (\n or \r))
apologies if your code is correct
I'm sorry the internet is bit slow . my files are not uploading.