0

I have the following structure of data

HG2 MET 
HG1 THR
HG2 THR
HG2 GLN

The desire output would be

HG1 MET 
HG1 THR
HG2 THR
HG1 GLN

somehow I need to do the following

for i in MET GLN
do
sed 's/HG2 $i/HG1 $i/g'
done

or if it is possible to specify that I do not want to change the HG2 for THR but still change all the other instead

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

2 Answers2

3

You can do the same with one run of sed for the whole file:

sed -E 's/HG2 (MET|GLN)/HG1 \1/' < oldfile > newfile
ilkkachu
  • 138,973
0

ok I found the solution by simply adding double quotes such as

sed "s/HG2 $i/HG1 $i/g"