1

This question already has an answer here:

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 Jun 27 '17 at 23:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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
1
$ 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
  • 2
    @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

Not the answer you're looking for? Browse other questions tagged or ask your own question.