Replace "/U+[0-9A-Fa-f]{4}/" with proper unicode character in shell pipeline with sed eval flag
With perl:
perl -CS -pe 's/\bU\+([\dA-Fa-f]{4})\b/chr(hex($1))/eg' /usr/include/X11/keysymdef.h
This tells perl to look for U+0000
, convert the 0000
to hex, and then replace it with the character represented by that number.
If you want to replace the contents of the file you can do:
perl -i -CD -pe 's/\bU\+([\dA-Fa-f]{4})\b/chr(hex($1))/eg' /path/to/file
Pass the (modified) sed output line-wise through echo -e ""
:
sed -e 's/U+\([0-9A-Fa-f]\{4\}\)/\\u\1/' </usr/include/X11/keysymdef.h |
while read -r line;do echo -e "$line";done