I want to replace multiple strings (more than thousand) in File-1 with matching string from File-2
File-1:
Geneid Length s1 s2
1_1 6571 7 8
1_2 5041 3 0
1_3 1032 7 3
1_4 1212 3 5
1_5 1071 3 5
2_1 7171 2 7
2_2 1038 1 1
2_3 9361 0 6
2_4 1056 5 1
File-2 (map):
1_1
1_2 k0002
1_3
1_4
1_5 k0006
2_1
2_2
2_3
2_4 k0528
Expected output:
Geneid Length s1 s2
1_1 6571 7 8
k0002 5041 3 0
1_3 1032 7 3
1_4 1212 3 5
k0006 1071 3 5
2_1 7171 2 7
2_2 1038 1 1
2_3 9361 0 6
k0528 1056 5 1
I used the following awk command:
awk '
NR==FNR {
a[$1]=$2
next
}
{
print (($1 in a)?a[$1]:$1, $2, $3, $4)
}' File-2 File-1 > File-3
which gives me this:
Geneid Length s1 s2
6571 7 8
k0002 5041 3 0
1032 7 3
1212 3 5
k0006 1071 3 5
7171 2 7
1038 1 1
9361 0 6
k0528 1056 5 1
How to modify this awk command to keep unmatched strings?
Sorry, I am a newbie to linux and awk (trying to learn).