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

  • Home
  • SEARCH
  • 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 7641425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:55:11+00:00 2026-05-31T08:55:11+00:00

How can I handle utf8 using Perl (or Python) on the command line? I

  • 0

How can I handle utf8 using Perl (or Python) on the command line?

I am trying to split the characters in each word, for example. This is very easy for non-utf8 text, for example:

$ echo "abc def" | perl -ne 'my @letters = m/(.)/g; print "@letters\n"' | less
a b c   d e f

But with utf8 it doesn’t work, of course:

$ echo "одобрение за" | perl -ne 'my @letters = m/(.)/g; print "@letters\n"' | less
<D0> <BE> <D0> <B4> <D0> <BE> <D0> <B1> <D1> <80> <D0> <B5> <D0> <BD> <D0> <B8> <D0> <B5>   <D0> <B7> <D0> <B0>

because it doesn’t know about the 2-byte characters.

It would also be good to know how this (i.e., command-line processing of utf8) is done in Python.

  • 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-31T08:55:12+00:00Added an answer on May 31, 2026 at 8:55 am

    The “-C” flag controls some of the Perl Unicode features (see perldoc perlrun):

    $ echo "одобрение за" | perl -C -pe 's/.\K/ /g'
    о д о б р е н и е   з а 
    

    To specify encoding used for stdin/stdout you could use PYTHONIOENCODING environment variable:

    $ echo "одобрение за" | PYTHONIOENCODING=utf-8 python -c'import sys
    for line in sys.stdin:
        print " ".join(line.decode(sys.stdin.encoding)),
    '
    о д о б р е н и е   з а 
    

    If you’d like to split the text on characters (grapheme) boundaries (not on codepoints as the code above) then you could use /\X/ regular expression:

    $ echo "одобрение за" | perl -C -pe 's/\X\K/ /g'
    о д о б р е н и е   з а 
    

    See Grapheme Cluster Boundaries

    In Python \X is supported by regex module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some numbers that is now larger than INT can handle. This is
How can i handle utf-8 string using gtk frame work.
I am using Perl to load some 'macro' files. These macros can, however, be
Suppose I am designing a class that can handle any database technology to create
I need a c# number something that can handle very large numbers but also
It is my understanding that one can handle events through Swing by adding a
Looking for a jQuery MultiSelect Widget that can handle thousands of items. Really like
Is there a pattern that can handle recurring dimension in data warehouse? I've got
I am looking for a searchable multiple select javascript widget that can handle filtering
I'd like to write a single JDBC statement that can handle the equivalent of

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.