2

I have a file containing text

**This is bold text** 
*This is italicized text*

I wish to convert the above into

  \textbf{This is bold text}
  \emph{This is italicized text}

using stream editor(sed). Kindly guide me on this matter.

I have used this code

sed -i 's/\*\*\(.*\)\*\*/\\textbf{\1}/g' SampleCode 

and it works like a charm

Thanks from Google group

pasmon
  • 51

2 Answers2

4

It looks like you are trying to invent new Pandoc.
Instead:

  1. Install Pandoc:

    sudo apt-get install pandoc
    
  2. Create input file:

    $ cat << EOF > file.md
    **This is bold text** 
    *This is italicized text*
    EOF
    
  3. Run conversion from Markdown to LaTeX:

    pandoc file.md -o file.tex
    
  4. Enjoy the result:

    $ cat file.tex 
    \textbf{This is bold text} \emph{This is italicized text}
    
dessert
  • 40,956
N0rbert
  • 103,263
0

This is the simple answer:

echo '**This is bold text**' | sed -r 's/\*\*(.+)\*\*/\\textbf{\1}/'
echo '*This is italicized text*' | sed -r 's/\*(.+)\*/\\emph{\1}/'

Most important thing is to understand regular expressions. There are several online regex testers where you can experiment with regex.

Here is a very good explanation of sed. https://www.grymoire.com/Unix/Sed.html