Village
Village

Reputation: 24383

How to delete any string beginning with a backslash?

I have a file containing much TeX mark-up, like this:

The fish ate 20\percent more food than the bear.
The fish ate \the\number\percent more food than the bear.

I want to delete that text which is a TeX code, like \percent and replace it with a space.

How can I delete the appearance of these items, which begin with \ and afterwards are followed by a space, {, or another \?

Upvotes: 2

Views: 120

Answers (1)

anubhava
anubhava

Reputation: 785146

You can use this perl command:

perl -pe 's#\\[^ \\{]+# #g' file.txt

OR using sed:

sed -E 's#\\[^ \\{]+# #g' file.txt

OR if -E is not supported then:

sed -r 's#\\[^ \\{]+# #g' file.txt

OUTPUT

The fish ate 20  more food than the bear.
The fish ate     more food than the bear.

Upvotes: 3

Related Questions