Sorry for the vagueness of the question, I hope the following explanation will be clear enough.
I often keep notes of my readings and most of these notes are composed of extracts of these readings. I was wondering if some emacs/org-mode function existed that would do the following: extract the parts from a text that are marked up. Let's say that the markup would be _
(could be any other symbol).
For example, consider the following text
Productivity is a crucial factor in the production performance of firms and nations.
Increasing national productivity can raise living standards because more real
income improves people's ability to purchase goods and services, enjoy leisure,
improve housing, and education and contribute to social and environmental programs.
Productivity growth can also help businesses to be more profitable.
During my reading, I will manually emphasize 3 passages:
Productivity is a crucial factor in the production performance of _firms and nations_.
Increasing national productivity _can raise_ living standards because more real
income improves people's ability to purchase goods and services, enjoy leisure,
improve housing, and education and contribute to social and environmental programs.
_Productivity_ growth can also help businesses to be more profitable.
The job of the function would be to extract the passages as follows:
firms and nations can raise Productivity
grep -o '_[^_]*_' /tmp/foo4.org
is a start: you only need to get rid of the surrounding underscores. The only problem is the usual one of underscores that are not markup. It should be easy to turn that into an Emacs function (if worse comes to worst, the function can run thegrep
command, more-or-less as is).grep -o '\*[^\*]*\*' ~/tmp/tmp.org > test.org
works well on a terminal, but from emacs,(shell-command-on-region b e "grep -o '\*[^\*]*\*' > ~/tmp/tm")
doesn't...*
inside a character class construct[...]
is not special and does not have to be escaped. In fact, trying to escape it as you have done, changes the meaning of the character class:"[^\\*]"
(the Emacs string form) meansany character other than backslash or asterisk
. It's always good to remember what JWZ said about regexps, even if you do decide to use them.(shell-command-on-region b e "grep -o '\\*[^*]*\\*' > ~/tmp/tmo")
worked perfectly (I updated the solution accordingly).