I would like to replace strings in a file following this pattern:
<<key q>>→<kbd>q</kbd><<key Ctrl q>>→<kbd>Ctrl</kbd>+<kbd>q</kbd><<key Ctrl Shift Alt q>>→<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Alt</kbd>+<kbd>q</kbd>
UPDATE: The file contains other text, too. Example: Press <<key Ctrl q>> to quit.
The best solution I could find for this problem is calling sed with separate scripts for 1, 2, 3 and 4 keys:
sed -i -E \
-e 's|<<key ([^ ]+)>>|<kbd>\1</kbd>|g'
-e 's|<<key ([^ ]+) ([^ ]+)>>|<kbd>\1</kbd>+<kbd>\2</kbd>|g' \
-e 's|<<key ([^ ]+) ([^ ]+) ([^ ]+)>>|<kbd>\1</kbd>+<kbd>\2</kbd>+<kbd>\3</kbd>|g' \
-e 's|<<key ([^ ]+) ([^ ]+) ([^ ]+) ([^ ]+)>>|<kbd>\1</kbd>+<kbd>\2</kbd>+<kbd>\3</kbd>+<kbd>\4</kbd>|g' \
file.txt
Obviously, this fails for macros containing 5 or more keys.
Is there a more generic solution that works for n keys? Not restricted to sed. I also tried using structural regular expressions (sregx) but couldn't find how to do it.
Ctrl,ShiftandAltare literal strings. Sorry for using confusing example strings. Next time I'll usefooandbarinstead.UPDATE: The file contains other text, too. Example: Press <<key Ctrl q>> to quit.- don't change your question after you got answers, please roll it back to what it was so as to not invalidate the answers you got.