Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 27 章 文本处理

目录

27.1. iconv - Convert encoding of given files from one encoding to another
27.1.1. cconv - A iconv based simplified-traditional chinese conversion tool
27.1.2. uconv - convert data from one encoding to another
27.2. 字符串处理命令expr
27.3. cat - concatenate files and print on the standard output
27.3.1. -s, --squeeze-blank suppress repeated empty output lines
27.3.2. -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
27.3.3. 与管道配合使用
27.4. nl - number lines of files
27.5. tr - translate or delete characters
27.5.1. 替换字符
27.5.2. 英文大小写转换
27.5.3. [CHAR*] 和 [CHAR*REPEAT]
27.5.4. -s, --squeeze-repeats replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character
27.5.5. -d, --delete delete characters in SET1, do not translate
27.6. cut - remove sections from each line of files
27.6.1. 字符操作
27.6.2. 列操作
27.7. printf - format and print data
27.8. Free `recode' converts files between various character sets and surfaces.
27.9. /dev/urandom 随机字符串
27.10. col - filter reverse line feeds from input
27.11. apg - generates several random passwords
27.12. head/tail
27.12.1. 彩色输出
27.12.2. 跳过 n 行,输出后面内容
27.12.3. 尾部剪掉 n 行
27.13. 反转字符串或文件内容
27.14. TAB符号与空格处理
27.14.1. expand - convert tabs to spaces
27.14.2. unexpand - convert spaces to tabs
27.15. grep, egrep, fgrep, rgrep - print lines matching a pattern
27.15.1. 删除空行
27.15.2. -v, --invert-match
27.15.3. 输出控制(Output control)
27.15.4. Context control
27.15.5. Regexp selection and interpretation
27.15.6. fgrep
27.15.7. egrep
27.16. sort - sort lines of text files
27.16.1. 对列排序
27.16.2. -s, --stable stabilize sort by disabling last-resort comparison
27.17. uniq
27.18. awk
27.18.1. 处理列
27.18.2. printf
27.18.3. Pattern(字符匹配)
27.18.4. Built-in Variables (NR/NF)
27.18.5. Built-in Functions
27.18.6. 过滤相同的行
27.18.7. 数组演示
27.19. sed
27.19.1. 查找与替换
27.19.2. insert 插入字符
27.19.3. 追加字符
27.19.4. 修改字符
27.19.5. 删除字符
27.19.6. 行操作
27.19.7. 编辑文件
27.19.8. 正则表达式
27.19.9. 管道操作
27.19.10. 字母大小写转换
27.19.11. perl
27.19.12. 案例
27.20. ed, red - text editor
27.21. vim
27.21.1. vim 初始化
27.21.2. 查找与替换
27.21.3. 删除操作
27.21.4. 插入文件
27.21.5. 批处理
27.21.6. line()
27.21.7. set fileformat
27.21.8. 空格与TAB转换
27.22. XML 工具
27.22.1. xmllint - command line XML tool
27.22.2. xmlstarlet - command line XML/XSLT toolkit
27.23. jq - Command-line JSON processor
27.23.1. --raw-output

27.1. iconv - Convert encoding of given files from one encoding to another

27.1.1. cconv - A iconv based simplified-traditional chinese conversion tool

cconv是建立在iconv之上,可以UTF8编码直接转换,并增加了词转换。

sudo apt-get install cconv
			

使用cconv进行简繁转换的方法为:

cconv -f UTF8-CN -t UTF8-HK zh-cn.txt -o zh-hk.txt
			

27.1.2. uconv - convert data from one encoding to another

安装

sudo apt-get install libicu-dev
			

例子

$ uconv -f cp1252 -t UTF-8 -o file_in_utf8.txt file_in_cp1252_encoding.txt