Issue
I want to replace
\usepackage[french]{babel}
by
\usepackage[french]{babel}
\addto\captionsfrench{\def\tablename{Tableau}}
so far, I came to:
#!/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
(append) 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}}
PS: Note that we are using double \\
after a
since main sed script is inside the double quotes.
Answered By - anubhava Answer Checked By - Gilberto Lyons (WPSolving Admin)