2
I am trying to produce index entries in a LaTeX file under Linux. I have two files: file1.txt
has all the index entries
cats\index{cat}
dogs\index{dog}
elephants\index{elephant}
rats\index{rat}
The animals.tex
file contains the story text.
elephants are afraid of rats but are not scared of cats and dogs.
How can I replace the different animals in the .tex file with the ones of the file1.txt? to get the following text:
Elephants\index{elephant} are afraid of rats\index{rat} but are not scared of cats\index{cat} and dogs\index{dog}.
I have tried some commands with grep and sed, but I was not successful. Any help is much appreciated.
I tried:
cat story.tex | grep "^.*" animals.tex | sed "s/.*$/&/" > story2.tex
No success.
Are you OK for a perl solution? – Toto – 2019-12-01T12:00:33.800