Issue
How to print only string figure
with the following line :
\begin{figure}[h!]
I tried :
firstLine='\begin{figure}[h!]'
echo $firstLine | sed -n 's/\\begin{\(.*\)}/\1/p'
but returns :
figure[h!]
instead of figure
It seems that issue comes from []
or !
character.
Solution
firstLine='\begin{figure}[h!]'
echo "$firstLine" | sed 's/.*{\(.*\)}.*/\1/'
Output:
figure
With your code (add .*
):
echo $firstLine | sed -n 's/\\begin{\(.*\)}.*/\1/p'
Answered By - Cyrus Answer Checked By - Marie Seifert (WPSolving Admin)