Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4124002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:41:04+00:00 2026-05-20T23:41:04+00:00

I’m doing some changes in Linux locale files /usr/share/i18n/locales (like pt_BR ), and it’s

  • 0

I’m doing some changes in Linux locale files /usr/share/i18n/locales (like pt_BR), and it’s required that format strings (like %d-%m-%Y %H:%M) must be specified in Unicode, where each (in this case, ASCII) character is represented as <U00xx>.

So a text like this:

LC_TIME
d_t_fmt "%a %d %b %Y %T %Z"
d_fmt   "%d-%m-%Y"
t_fmt   "%T"

Must be:

LC_TIME
d_t_fmt "<U0025><U0061><U0020><U0025><U0064><U0020><U0025><U0062><U0020><U0025><U0059><U0020><U0025><U0054><U0020><U0025><U005A>"
d_fmt   "<U0025><U0064><U002D><U0025><U006D><U002D><U0025><U0059>"
t_fmt   "<U0025><U0054>"

Thus I need a command-line script (be it bash, Python, Perl, or something else) that would take an input like %d-%m-%Y and convert it to <U0025><U0064><U002D><U0025><U006D><U002D><U0025><U0059>.

All characters in the input string would be ASCII chars (from 0x20 to 0x7F), so this is actually a fancier “char-to-hex-string” conversion.

Could anyone please help me? My skills in bash scripting are very limited, and even worse in Python.

Bonus for elegant, explained solutions.

Thanks!

(by the way, this would be the “reverse” script for my previous question)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:41:04+00:00Added an answer on May 20, 2026 at 11:41 pm

    Every char with file input

    If you wanted to convert every character of a file to the unicode representation, then it would be this simple one-liner

    while IFS= read -r -n1 c;do printf "<U%04X>" "'$c"; done < ./infile
    

    Every char on STDIN

    If you want to make a unix-like tool which converts input on STDIN to unicode-like output, then use this:

    uni(){ c=$(cat); for((i=0;i<${#c};i++)); do printf "<U%04X>" "'${c:i:1}"; done; }
    

    Proof of Concept

    $ echo "abc" | uni
    <U0061><U0062><U0063>
    

    Only chars between double-quotes

    #!/bin/bash
    
    flag=0
    while IFS= read -r -n1 c; do
        if [[ "$c" == '"' ]]; then
            ((flag^=1))
            printf "%c" "$c"
        elif [[ "$c" == $'\0' ]]; then
            echo
        elif ((flag)); then
            printf "<U%04X>" "'$c"
        else
            printf "%c" "$c"
        fi
    done < /path/to/infile
    

    Proof of Concept

    $ cat ./unime
    LC_TIME
    d_t_fmt "%a %d %b %Y %T %Z"
    d_fmt   "%d-%m-%Y"
    t_fmt   "%T"
    abday "Dom";"Seg";/
    here is a string with "multiline
    quotes";/
    
    $ ./uni.sh
    LC_TIME
    d_t_fmt "<U0025><U0061><U0020><U0025><U0064><U0020><U0025><U0062><U0020><U0025><U0059><U0020><U0025><U0054><U0020><U0025><U005A>"
    d_fmt   "<U0025><U0064><U002D><U0025><U006D><U002D><U0025><U0059>"
    t_fmt   "<U0025><U0054>"
    abday "<U0044><U006F><U006D>";"<U0053><U0065><U0067>";/
    here is a string with "<U006D><U0075><U006C><U0074><U0069><U006C><U0069><U006E><U0065>
    <U0071><U0075><U006F><U0074><U0065><U0073>";/
    

    Explanation

    Pretty simply really

    1. while IFS= read -r -n1 c;: Iterate over the input one character at a time (via -n1) and store the char in the variable c. The IFS= and -r flags are there so that the read builtin doesn’t try to do word splitting or interpret escape sequences, respectively.
    2. if [[ "$c" == '"' ]];: If the current char is a double-quote
    3. ((flag^=1)): Invert the value of flag from 0->1 or 1->0
    4. elif [[ "$c" == $'\0' ]];: If the current char is a NUL, then echo a newline
    5. elif ((flag)): If flag is 1, then perform unicode transliteration
    6. printf "<U%04X>" "'$c": The magic that does the unicode transliteration. Note that the single-quote before the $c is mandatory as it tells printf that we are giving it the ASCII representation of a number.
    7. else printf "%c" "$c": Print out the character with no unicode transliteration performed
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.