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
  • 66,199
  • 35
  • 114
  • 250
Dimitris Mintis
  • 543
  • 1
  • 4
  • 15

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
  • 133,243
  • 15
  • 236
  • 397
0

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

sed "s/HG2 $i/HG1 $i/g"
Dimitris Mintis
  • 543
  • 1
  • 4
  • 15