# AWK/SED Remove a specific latex command from the text AND closing bracket behind it [duplicate]

How to remove a specific latex command from the text AND closing bracket behind it, but to keep the text inside the brackets/

Please fill free to suggest SED, or AWK, or Perl or whatever will do the job

Input sensless example:

We \edit{Introduce a} model for analyzing \emph{data} from various
experimental designs, \edit{such as 23 paired or longitudinal}.


Output:

We Introduce a model for analyzing \emph{data} from various
experimental designs, such as 23 paired or longitudinal.


PS. I am introducing a lot of small edits into my tex file. I want those edits to be highlighted, so my collaborator can see them. But afterwards I would like to remove all highlights with one or two commands.

## marked as duplicate by Gilles text-processing StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jun 27 '17 at 23:05

• you can do it with sed if you know about things like meta characters, character classes and capture groups... or perhaps there is a latex aware cli tool... do try to solve it yourself before asking.. – Sundeep Jun 27 '17 at 13:24
• ... sorry, but your input always changes... a reliable sample would be appreciate. – John Goofy Jun 27 '17 at 13:42
• Sorry, my fault. Now the example is representative. – den2042 Jun 27 '17 at 13:56
• It appeared that my example was again too soft . Here is more realistic one: unix.stackexchange.com/questions/373772/… – den2042 Jun 27 '17 at 21:48
• See ilkkachu answer to unix.stackexchange.com/questions/373772/… – den2042 Jun 27 '17 at 22:55

$cat file We \edit{introduce a} model for analyzing data from various experimental designs, \edit{such as paired or longitudinal}.$ sed 's/$$\\edit{$$$$[a-z ]*$$$$}$$/\2/g' file
We introduce a model for analyzing data from various
experimental designs, such as paired or longitudinal.


If your file look like this:

$cat file We \edit{Introduce a} model for analyzing \emph{data} from various experimental designs, \edit{such as 23 paired or longitudinal}.  Then you should try: sed 's/$$\\[a-z]*{$$$$[A-Za-z0-9 ]*$$$$}$$/\2/g' file We Introduce a model for analyzing data from various experimental designs, such as 23 paired or longitudinal.  If you want to keep \emph{data} then use: $ sed 's/$$\\edit{$$$$[A-Za-z0-9 ]*$$$$}$$/\2/g' file
We Introduce a model for analyzing \emph{data} from various
experimental designs, such as 23 paired or longitudinal.


Or a more smooth way:

\$ sed 's/\\edit{$$[^}]*$$}/\1/g' file

• sed 's/$$\\edit{$$$$[a-zA-Z0-9 ]*$$$$}$$/\2/g' file Thank you. I've made too narrow example – den2042 Jun 27 '17 at 13:38
• ... sorry, but the input example always changes... – John Goofy Jun 27 '17 at 13:40
• My fault. Your solution works perfect (apart from technical trivial issue with digits, which where not in the initial example). Thank you very much indeed. – den2042 Jun 27 '17 at 13:48
• \edit Should stay in the second case as well. But I've got the idea. Thank you very much indeed – den2042 Jun 27 '17 at 14:00
• @JohnGoofy instead of aiming to match valid characters between {}, you can simply match other than }... for ex: sed 's/\\edit{$$[^}]*$$}/\1/g' – Sundeep Jun 27 '17 at 14:33