A fully portable solution could look like:
n='
';printf %s\\n muller wright dummy >/tmp/patterns
tr '[:lower:][:upper:]' '[:upper:][:lower:]' </tmp/patterns |
paste '-d\n\n' - /tmp/patterns |
sed "N;s/./\\$n&/;:ul$n s/\(\n\)\(.\)\(.*\n\)\(.\)/\2\4\1\3/;tul"'
s/\n//g;s/../[{}\\"]*[&]/g'
The output from that last sed
looks like:
[{}\"]*[mM][{}\"]*[uU][{}\"]*[lL][{}\"]*[lL][{}\"]*[eE][{}\"]*[rR]
[{}\"]*[wW][{}\"]*[rR][{}\"]*[iI][{}\"]*[gG][{}\"]*[hH][{}\"]*[tT]
[{}\"]*[Dd][{}\"]*[uU][{}\"]*[Mm][{}\"]*[mM][{}\"]*[Yy]
It would depend on the contents of patterns being only alphanumeric characters. If patterns contained, for example, either of []
it would require further testing to ensure that the square brackets were placed correctly each within their respective bracket expressions.
In any case, based on the example in question:
[{}\"]*[mM][{}\"]*[uU][{}\"]*[lL][{}\"]*[lL][{}\"]*[eE][{}\"]*[rR]
...is a regexp that will match a line containing any of muller
or Muller
or M"ulL\\\{"er
.
With GNU sed
you can handle the case conversions within sed
itself, so:
sed -E 's/([[:upper:]]?)([[:lower:]]?)/\1\L\1\2\U\2/g' patterns
...prints...
mMuUlLlLeErR
wWrRiIgGhHtT
DduUMmmMYy
...fully fleshed out, you can get the same behavior as the previous tr|paste|sed
combination (except that, this way, the aforementioned square-bracket problem is handled correctly) with just GNU sed
like:
sed -E '
s/([[:lower:]]?)([[:upper:]]?)/\1\U\1\2\L\2/g
s/[[:alpha:]]{2}|./[{}\\"]*[&]/g
' </tmp/patterns
bib2bib
tool? – daniel kullmann Mar 16 '15 at 21:46