How to find the last 2 characters of Chinese names with command lines tools?

1

I have a list of Chinese names, some of them have 2 characters, others may have more or less, like following:

enter image description here

I want to use some command lines tools, to find the last 2 characters of each. If doesn't 2 characters, ignore it.

The result will be:

enter image description here

How to do it with grep/awk/sed, or other tools?


Updated:

The characters are in gist now:

https://gist.github.com/freewind/6e67b76e8280ccea185c

Freewind

Posted 2015-11-05T10:23:55.763

Reputation: 1 547

2@stackoverflow, can you stop thinking I'm spamming just because I've input some Chinese characters ?! – Freewind – 2015-11-05T10:24:36.767

Can you paste the actual input? We can't test our solutions against images. – choroba – 2015-11-05T10:26:04.057

Answers

2

Perl to the rescue:

perl -CSD -lne 'print $1 if /(..)$/' input-file
  • -CSD turns UTF-8 on for input and output on STDIN, STDOUT and input and output streams.
  • -l appends newline to print
  • -n reads the input line by line

choroba

Posted 2015-11-05T10:23:55.763

Reputation: 14 741

1-CIO turns utf8 on for stdin and stdout. -Cio turns :utf8 on for PerlIO's file input and output. You probably want -CIOio – Matt – 2015-11-06T00:09:29.990