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

第 25 章 文本处理

目录

25.1. iconv - Convert encoding of given files from one encoding to another
25.1.1. cconv - A iconv based simplified-traditional chinese conversion tool
25.1.2. uconv - convert data from one encoding to another
25.2. 字符串处理命令expr
25.3. cat - concatenate files and print on the standard output
25.3.1. -s, --squeeze-blank suppress repeated empty output lines
25.3.2. -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
25.3.3. 与管道配合使用
25.4. nl - number lines of files
25.5. tr - translate or delete characters
25.5.1. 替换字符
25.5.2. 英文大小写转换
25.5.3. [CHAR*] 和 [CHAR*REPEAT]
25.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
25.5.5. -d, --delete delete characters in SET1, do not translate
25.6. cut - remove sections from each line of files
25.6.1. 字符操作
25.6.2. 列操作
25.7. printf - format and print data
25.8. Free `recode' converts files between various character sets and surfaces.
25.9. /dev/urandom 随机字符串
25.10. col - filter reverse line feeds from input
25.11. apg - generates several random passwords
25.12. head/tail
25.12.1. 彩色输出
25.12.2. 跳过 n 行,输出后面内容
25.12.3. 尾部剪掉 n 行
25.13. 反转字符串或文件内容
25.14. TAB符号与空格处理
25.14.1. expand - convert tabs to spaces
25.14.2. unexpand - convert spaces to tabs
25.15. grep, egrep, fgrep, rgrep - print lines matching a pattern
25.15.1. 删除空行
25.15.2. -v, --invert-match
25.15.3. 输出控制(Output control)
25.15.4. Context control
25.15.5. Regexp selection and interpretation
25.15.6. fgrep
25.15.7. egrep
25.16. sort - sort lines of text files
25.16.1. 对列排序
25.16.2. -s, --stable stabilize sort by disabling last-resort comparison
25.17. uniq
25.18. awk
25.18.1. 处理列
25.18.2. printf
25.18.3. Pattern(字符匹配)
25.18.4. Built-in Variables (NR/NF)
25.18.5. Built-in Functions
25.18.6. 过滤相同的行
25.18.7. 数组演示
25.19. sed
25.19.1. 查找与替换
25.19.2. insert 插入字符
25.19.3. 追加字符
25.19.4. 修改字符
25.19.5. 删除字符
25.19.6. 行操作
25.19.7. 编辑文件
25.19.8. 正则表达式
25.19.9. 管道操作
25.19.10. 字母大小写转换
25.19.11. perl
25.19.12. 案例
25.20. ed, red - text editor
25.21. vim
25.21.1. vim 初始化
25.21.2. 查找与替换
25.21.3. 删除操作
25.21.4. 插入文件
25.21.5. 批处理
25.21.6. line()
25.21.7. set fileformat
25.21.8. 空格与TAB转换
25.22. XML 工具
25.22.1. xmllint - command line XML tool
25.22.2. xmlstarlet - command line XML/XSLT toolkit
25.23. jq - Command-line JSON processor
25.23.1. --raw-output

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

25.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
			

25.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