I have 2 files (FileA & FileB),
FileA:
s12 >g01
s16 >g02
s48 >g03
s52 >g04
s80 >g05
s81 >g06
s87 >g07
s91 >g08
s92 >g09
s93 >g10
s94 >g11
s96 >g12
s97 >g13
s98 >g14
s99 >g15
s100 >g16
FileB:
s12:1148.1652412 [PCC6803]
ABCDEFGHIJKLMNOPQRST
s16:1235.1653193 [PCC6803]
UVWXYZABCDEFGHIJKLMN
s48:5877.1652308 [PCC6803]
OPQRSTUVWXYZABCDEFGH
.
.
.
I wanted to edit FileB so that all "column 1 strings from FileA" that exist in FileB will be changed to "column 2 strings from FileA"
Desired output:
>g01 [PCC6803]
ABCDEFGHIJKLMNOPQRST
>g02 [PCC6803]
UVWXYZABCDEFGHIJKLMN
>g03 [PCC6803]
OPQRSTUVWXYZABCDEFGH
I will need to process the editing for around 20 files that are in the same format as FileB.
Is there any command that can do this kind of editing? And doing it simultaneously or using one line command in Linux terminal? Thanks in advance!
Update: I have tried the example from Replace multiple strings with different set of mapped strings but it doesn't work.
replacements=(
s12:\>g01
s16:\>g02
s48:\>g03
s52:\>g04
s80:\>g05
s81:\>g06
s87:\>g07
s91:\>g08
s92:\>g09
s93:\>g10
s94:\>g11
s96:\>g12
s97:\>g13
s98:\>g14
s99:\>g15
s100:\>g16
)
for row in "${replacement[@]}"; do
original="$(echo $row | cut -d: -f1)";
new="$(echo $row | cut -d: -f2)";
sed -i -e "s/${original}/${new}/g" FileB;
done
:
(e.g.s12:
) in fileB? – terdon Jun 10 '19 at 08:08