We have files with some chars represented by decimal(!) ascii values enclosed in cid(#) as e.g. (cid:104) for h. The string hello is thus represented as (cid:104)(cid:101)(cid:108)(cid:108)(cid:111).
How can I substitute this with the corresponding ascii characters using sed?
Here is an example file:
$ cat input.txt first line pre (cid:104)(cid:101)(cid:108)(cid:108)(cid:111) post last line What I've tried so far is:
$ x="(cid:104)(cid:101)(cid:108)(cid:108)(cid:111)" $ echo $x | sed 's/(cid:\([^\)]*\))/\1/g' 104101108108111 But wee need the output to be hello
$ cat output.txt first line pre hello post last line I'm trying to use printf in sed. But cannot find out how to pass the backreference \1 to printf
sed 's/(cid:\([^\)]*\))/'`printf "\x$(printf %x \1)"`'/g'