Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Insert a string on a new line after a pattern

I want to replace

\usepackage[french]{babel}

by

\usepackage[french]{babel}
\addto\captionsfrench{\def\tablename{Tableau}}
                  

so far, I came to:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 #!/bin/bash                                                                                                              
 newString='\\addto\\captionsfrench{\\def\\tablename{Tableau}}'                                                                                                                                              
 sed -i "/babel.*/a $newString"  $1    

which almost does the job
The problem I encounter is that if I write newString=’\addto\captionsfrench{\def\tablename{Tableau}}’ the backslash before \addto is absent, and if I escape the backslash \addto I obtain ^Gaddto
~

>Solution :

This sed should work for you with a sed command:

cat file

\usepackage[french]{babel}

newString='\\addto\\captionsfrench{\\def\\tablename{Tableau}}'
sed -i.bak "/{babel}/a\\
$newString
" file

cat file

\usepackage[french]{babel}
\addto\captionsfrench{\def\tablename{Tableau}}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading