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

第 7 章 文本处理

目录

7.1. iconv - Convert encoding of given files from one encoding to another
7.1.1. cconv - A iconv based simplified-traditional chinese conversion tool
7.1.2. uconv - convert data from one encoding to another
7.2. 字符串处理命令expr
7.3. cat - concatenate files and print on the standard output
7.3.1. -s, --squeeze-blank suppress repeated empty output lines
7.3.2. -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
7.3.3. 与管道配合使用
7.4. nl - number lines of files
7.5. tr - translate or delete characters
7.5.1. 替换字符
7.5.2. 英文大小写转换
7.5.3. [CHAR*] 和 [CHAR*REPEAT]
7.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
7.5.5. -d, --delete delete characters in SET1, do not translate
7.6. cut - remove sections from each line of files
7.6.1. 字符操作
7.6.2. 列操作
7.7. printf - format and print data
7.8. Free `recode' converts files between various character sets and surfaces.
7.9. /dev/urandom 随机字符串
7.10. col - filter reverse line feeds from input
7.11. apg - generates several random passwords
7.12. head/tail
7.12.1. 彩色输出
7.12.2. 跳过 n 行,输出后面内容
7.12.3. 尾部剪掉 n 行
7.13. 反转字符串或文件内容
7.14. TAB符号与空格处理
7.14.1. expand - convert tabs to spaces
7.14.2. unexpand - convert spaces to tabs
7.15. grep, egrep, fgrep, rgrep - print lines matching a pattern
7.15.1. 删除空行
7.15.2. -v, --invert-match
7.15.3. 输出控制(Output control)
7.15.4. Context control
7.15.5. Regexp selection and interpretation
7.15.6. fgrep
7.15.7. egrep
7.16. sort - sort lines of text files
7.16.1. 对列排序
7.16.2. -s, --stable stabilize sort by disabling last-resort comparison
7.17. uniq
7.18. awk
7.18.1. 处理列
7.18.2. printf
7.18.3. Pattern(字符匹配)
7.18.4. Built-in Variables (NR/NF)
7.18.5. Built-in Functions
7.18.6. 过滤相同的行
7.18.7. 数组演示
7.19. sed
7.19.1. 查找与替换
7.19.2. insert 插入字符
7.19.3. 追加字符
7.19.4. 修改字符
7.19.5. 删除字符
7.19.6. 行操作
7.19.7. 编辑文件
7.19.8. 正则表达式
7.19.9. 管道操作
7.19.10. 字母大小写转换
7.19.11. perl
7.19.12. 案例
7.20. ed, red - text editor
7.21. vim
7.21.1. vim 初始化
7.21.2. 查找与替换
7.21.3. 删除操作
7.21.4. 插入文件
7.21.5. 批处理
7.21.6. line()
7.21.7. set fileformat
7.21.8. 空格与TAB转换
7.22. XML 工具
7.22.1. xmllint - command line XML tool
7.22.2. xmlstarlet - command line XML/XSLT toolkit
7.23. jq - Command-line JSON processor
7.23.1. --raw-output

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

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

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