/^\s*[^@%]/
Apply the search-and-replace rule to lines that start (^) with zero or more white spaces (\s*), followed by any character ([...]) that is *NOT* a "@" or a "%" (^@%).
s=<some stuff>=<other stuff>=g
Search (s) for some stuff and replace by other stuff. Do that globally (g) for all matches in each processed line.
\([A-Z][A-Z]*\)\([^}A-Z]\|},$\)
Matches at least one uppercase letter ([A-Z][A-Z]*) followed by a character that is EITHER not "}" and not a capital letter ([^}A-Z]) OR (|) it actually IS a "}", which is followed by "," at the end of the line ($).
Putting regular expressions in escaped parentheses (\( and \), respectively) allows to dereference the matched string later.
{\1}\2
Replace the matched string by "{", followed by part 1 of the matched string (\1), followed by "}", followed by the second part of the matched string (\2).
I tried this with GNU sed, only, version 4.2.1.
@ARTICLE{Duck06, author = {{D}onald {D}uck and {D}aisy {D}uck and {S}crooge {M}c{D}uck}, title = {{T}he danger of magnetic storms for {D}uckburg}, journal = {{D}uckburg {T}ribune}, year = {2006}, volume = {56}, pages = {386--394}, number = {2}, month = {{A}ug}, owner = {{D}ucky {D}uke} }
Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?
You must be signed in to comment.
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
[^}A-Z]\|},$
which was designed to match capitals like intitle = {an upper case letter A},
has the disadvantage that it also matches A and B here:abstract = { lorem ipsum A,
dolor sit amet wtf C
consectetur adipiscing elit B,
...
}
How to fix...?abstract = { lorem ipsum {A},
dolor sit amet wtf {C}
consectetur adipiscing elit {B},
...
}
So after applying sed we have that:abstract = { lorem ipsum {{A}},
dolor sit amet wtf {C}
consectetur adipiscing elit {{B}},
...
}