Thanks to all of you. This is what finally worked for me:

CONFIG='Get_Homologues/Renamed_Prokka/control.txt'
DIRECTORY='Get_Homologues/Renamed_Prokka/Genomes'

# These are the strings to be found in the files
SOURCE1='Genus'
SOURCE2='species'
SOURCE3='strain\.'
SOURCE4='\"strain\"'

# Skip the first line with the titles of the columns
DATA=`tail -n +2 $CONFIG`

while IFS= read -r LINE
do
   # Get the columns of the config file and store them into separate variables
   FILENAME=`echo $LINE | awk '{print $1}'`
   REPLACE1=`echo $LINE | awk '{print $2}'`
   REPLACE2=`echo $LINE | awk '{print $3}'`
   REPLACE3=`echo $LINE | awk '{print $4}'`

   # Now replace each of the strings one by one, directly inside the file
   sed -i "" "s/$SOURCE1/$REPLACE1/g" $DIRECTORY/$FILENAME
   sed -i "" "s/$SOURCE2/$REPLACE2/g" $DIRECTORY/$FILENAME
   sed -i "" "s/$SOURCE3/$REPLACE3./g" $DIRECTORY/$FILENAME
   sed -i "" "s/$SOURCE4/\"$REPLACE3\"/g" $DIRECTORY/$FILENAME
done < <(printf '%s\n' "$DATA")

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top