# function : Give Way GBK Encoded files can be used less Normal display of Chinese ( Automatic identification GBK and UTF-8 code )
#v0. stay LINUX Next , Use UTF-8 code ,less UTF-8 The file is displayed in Chinese normally , and less GBK Garbled code will be displayed when the file is saved ,
# This script uses enca Identification code (enca The ability to recognize coding is weak , There are often cases of non recognition , In this case , Think it's GBK file ), If it is UTF-8 code ,
# Direct display ; If it is GBK code , First convert to UTF-8 code , Re display .
#v0. Add support for standard input redirection
#@todo How to let less Keep the original color ? res=$(lsof -a -p $$ -d0 >&)
if echo "$res" | grep -q "pipe" ; then
data=$(cat -) #- Represents standard input
if [ $# -eq ] ; then
echo "usage:$0 <file>"
fi if [ ! -e "$1" ] ; then
echo "$1 not exists"
fi if [ -d "$1" ] ; then
echo "$1 is a directory"
data=$(cat "$1")
fi gbk=
enc=$(echo "$data" | enca > /dev/null) # When the file is not recognized , The output will write stderr, Redirect to /dev/null
# Consider the unrecognized file as GBK file
if [ ! $? -eq ] ; then
elif echo $enc | grep -q GB ; then
# Convert files
if [ $gbk -eq ] ; then
data=$(echo "$data" | iconv -f gbk -t utf-)
echo "$data" | less
echo $data | less

cnless.sh: Improved version less, Can automatically identify GBK Encoding or UTF-8 code . More articles about

  1. The number of bytes occupied by encoding 1 byte 8 bit 1 sh 1 bit Chinese character encoding 2. The realization of character and code in program Variable length coding Unicode UTF-8 transformation Over the network Save to disk bytes

    Summary : 1.UNICODE There are many standards for character set coding , such as :UTF-8, UTF-7, UTF-16, UnicodeLittle, UnicodeBig etc. : 2 The server -> Webpage utf-8 ...

  2. GB2312、GBK and UTF-8 Three codes and QT Chinese display garbled problem

    1.GB2312.GBK and UTF-8 A brief description of the three codes GB2312.GBK and UTF-8 It's all a character encoding , besides , And a lot of character coding . Just for our Chinese applications , With these three codes More . Simply put , ...

  3. Say goodbye to garbled code , in the light of GBK、UTF-8 The intelligence of two codes URL Decoder java Realization ( turn )

    design sketch character Characters exist before computers , From the time of civilization , People use symbols to represent everything in the world . Such as ABC, Such as “ One . Two . 3、 ... and ”. Character set A character set is a set of all characters . XXX Character set Put an order on each character in the character set ...

  4. Sort out coding knowledge (UTF-8, Unicode, GBK, X509, ANSI, VIM Code in )

    Code summary 1 Get to know the code The so-called coding , It's the process of transforming information from one form or format to another . Character encoding , From a set of natural language characters ( Such as alphabet or syllabary ), To a collection of other things ( Such as number or electric pulse ) Mapping ANSI:wi ...

  5. Linux View the file code and batch modify the code

    Look at the file code in Linux You can view the file encoding in the following ways :1. stay Vim You can view the file code directly in :set fileencoding The file encoding format is displayed . If you just want to view files in other encoding formats or want to solve the problem with Vi ...

  6. Signature 、BOM head 、 code 、Windows Notepad code 、java Coding and decoding things

    about Windows Notepad : ANSI :GB2312 java Shall be used in GBK decode Unicode : Signed UTF-16LE java Shall be used in UTF-16 decode Unicode big endian : ...

  7. url code (percentcode Percent code )( Reprint )

    Original address :http://www.cnblogs.com/leaven/archive/2012/07/12/2588746.html   http://www.imkevinyang.com/2009 ...

  8. from Java String Examples to understand ANSI、Unicode、BMP、UTF And so on

    turn (http://www.codeceo.com/article/java-string-ansi-unicode-bmp-utf.html#0-tsina-1-10971-397232819ff9a ...

  9. 【 code 】_C# Code name in (Name) And page identification (CodePage) The relationship between _ code gb2312 Acquisition

    Writing C# Code , Find out VS Offer not directly offer gb2312 The Chinese code of , therefore , You need to find the corresponding encoding name codepage To call the desired encoding . Here's all the coding information provided by Microsoft programming , Including the code name , Code page identifier , ...

Random recommendation

  1. js Judge the selected time ( Or the current time ) Whether to display different customer service in different time periods in a certain time period qq

    //qq conversation var nowtimes= new Date(); var starttimes="16:30"; var endtimes="23:59"; v ...

  2. Ubuntu If you can't recognize the display , High resolution settings

    install ubuntu after , An unrecognized display appears , This makes it impossible to set high resolution . The interface looks like an elderly machine ,5.3 The vision of + Obsessive compulsive disorder , My concubine's heart is very refuse , After a long time, it's finally done , Here's the method . ( One ) Use xrandr command , ...

  3. Microsoft official website online compatibility test platform -Browser screenshots

    The last thing you want to do in front-end development is in different browsers . Platform and resolution test page display effect , Usually, there are a lot of problems that arise , In particular, the browser version may make the display effect completely different , We have to try our best to keep every kind of device can browse the web normally . There is no problem at all. We have to put in ...

  4. Win2008 On .NET4.0 Deployment error HTTP error 500.21 - Internal Server Error Solutions for

    reason : In the installation Framework v4.0 after , Re enable IIS, Lead to Framework Not completely installed solve : Start -> All the procedures -> The attachment -> Right click “ Command prompt ”-> Run as administrator ...

  5. C Language to draw cosine function image

    #include"stdio.h" #include"math.h" void main() { double y; int x,m; for(y=1;y> ...

  6. hhgis drive

    function loadPathInfo stay car.js in function loadPathInfo(carid, fnClass) { var qureydrive; if (jsonp) qu ...

  7. 【 Two points answer nlogn/ Standard solution O(n)】【UVA1121】Subsequence

    A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, a ...

  8. STL Source code analysis Algorithm stl_algo.h -- binary_search

    This paper is about senlie original . Please keep this address for reprint :http://blog.csdn.net/zhengsenlie binary_search -------------------------------- ...

  9. MongoDB Series two ( Introduce ).

    One . characteristic Learn a thing , At least first know what it can do ? What is suitable for ? What are the advantages and disadvantages ? Traditional relational databases , Follow three paradigms . Atomicity . Uniqueness . Each column is directly associated with the primary key . But then people slowly discovered that , Don't spread this data across multiple tables ...

  10. mysql Advanced ( Twelve ) Summary of common errors

    reason : Foreign key name cannot be repeated