Lukap
Lukap

Reputation: 31973

How to convert UTF-8 to Unicode

I have some file with encoding utf-8 like this

están

and I want to convert it to something like this

\u0065\u0073\u0074\u00E1\u006E

How can I make this conversion in bash ? I installed iconv but I did not managed to convert this

Upvotes: 1

Views: 507

Answers (1)

konsolebox
konsolebox

Reputation: 75618

With Ruby you can have:

ruby -e "print File.read(ARGV.shift).unpack('U*').map{ |i| '\u' + i.to_s(16).upcase.rjust(4, '0') }.join" your_file

Or for strings:

ruby -e "puts ARGV.shift.unpack('U*').map{ |i| '\u' + i.to_s(16).upcase.rjust(4, '0') }.join" "your string"

Upvotes: 1

Related Questions