sed : swap 2 lines of text into legend from matplotlib

53 views Asked by At

I have the following PDF produced from matplotlib :

pdf with legend to swap

I have inverted in the legend, during the generation of this plot, the lines "Observed data" and "Model".

I would like to swap them to be right.

From this link :

How to swap text based on patterns at once with sed?

I tried to inspire me and to do in a shell script :

cp -p $1 back_"$1"
qpdf --stream-data=uncompress $1 uncompressed.pd
gsed 's/Observed\ data/zz/g;s/Model/Observed\ data/g;s/zz/Model/g' uncompressed.pdf > temp_uncompressed.pdf
qpdf --stream-data=compress temp_uncompressed.pdf back_"$1"
rm -f uncompressed.pdf temp_uncompressed.pdf
mv -f back_"$1" $1

and execute by simply : $ ./myShell fit.pdf

Unfortunately, the swapping is not performed and I can't see where is the error.

If someone could see what's wrong ...

And from my first tests, this shell script produces warnings or errors and I don't know if I can avoid to get them.

1

There are 1 answers

2
guizmo133 On

Sorry, I have just done it in a simplier way :

cp -p $1 back_"$1"
qpdf --stream-data=uncompress $1 uncompressed.pdf
gsed -i 's/Observed\ data/zz/g' uncompressed.pdf
gsed -i 's/Model/Observed\ data/g' uncompressed.pdf
gsed -i 's/zz/Model/g' uncompressed.pdf
qpdf --stream-data=compress uncompressed.pdf back_"$1"
rm -f uncompressed.pdf
mv -f back_"$1" $1