Artificial intelligent assistant

How to add a dot to particular lines in LaTeX-document? I have a LaTeX-document where I have lines of the form \section*{3.1} \addcontentsline{toc}{section}{3.1} or in general \section*{x.y} \addcontentsline{toc}{section}{x.y} for x between 1 and 31 and y between 1 and 12 inclusively, (dates). I would like to change those lines to the form \section*{x.y.} \addcontentsline{toc}{section}{x.y.} Is there some easy script to do that?

You can use sed, match the before and after parts of the line and put a `.` in the middle. The command `s/ _REGEXP_ / _REPLACEMENT_ /` performs a regular expression replacement. `\(…\)` delimits a group; `\1` and `\2` in the replacement text refer to these groups.


sed replaced.tex \
-e 's/^\(\\section\\*{[0-9]*\.[0-9]*\)\(}\)$/\1.\2/' \
-e 's/^\(\\addcontentsline{toc}{section}{[0-9]*\.[0-9]*\)\(}\)$/\1.\2/'


Another way to use sed is to replace the last `}` by `.}` if the line matches the desired pattern:


sed replaced.tex \
-e '/^\\section\\*{[0-9]*\.[0-9]*}\)$/ s/}$/.&/' \
-e '/^\\addcontentsline{toc}{section}{[0-9]*\.[0-9]*}/ s/}$/.&/'


You can also use `\|` to combine two patterns but in this case I think it makes the code shorter but less clear.

If you want to replace the file in place, under Linux, you can use


sed -i -e … somefile.tex

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2d74a9618a97add5f274b734bded0f48