文本处理工具
1、排序文本
sort sort lines of text files
-b, --ignore-leading-blanks
ignore leading blanks
-d, --dictionary-order
consider only blanks and alphanumeric characters
-c, --check, --check=diagnose-first
check for sorted input; do not sort
-t, char
使用单个字符char作为默认的字段分割字符
-K a.b,c.d 表示从第a.b个字段开始比较到c.d
od 用ascii和8进制码来显示
2、字段排序
ex
反向UID排序
sort -t: -k3nr /etc/passwd
ex
以GID与UID排序
sort -t: -k4n -k3n /etc/passwd
ex
以唯一的GID排序
sort -t: -k4n -u /etc/passwd -u的好处是输出唯一的记录
3、文本块排序
这种情况下没有键值可以供-k来使用,所以得提供一些额外标记
木有看懂啊。。。。就是先做一些标记。。
4、删除重复
可以利用 uniq
sort example | uniq 显示唯一的
-c计数唯一的
-d显示重复的
-u显示唯一的
uniq可以哪来跟diff工具一起使用
5、重新格式化段落
fmt指令
ex
sed -n -e 9995,10004p /usr/share/dict/words | fmt -w 30
sed -n -e 9995,10004p /usr/share/dict/words | fmt
fmt -s -w 10 仅重新格式化长的行 -s指令控制
6、计算行数,字数和字符数
wc
-c, --bytes
print the byte counts
-m, --chars
print the character counts
-l, --lines
print the newline counts
-w, --words
print the word counts
7、提取开头或结尾数行
开头:
head -n
awk 'FNR<=n'
sed -e nq
sed nq
结尾
tail -n
8、其他值得注意的工具
dd 块大小拷贝工具
file 识别文件类型
od 八进制转储
strings
1、排序文本
sort sort lines of text files
-b, --ignore-leading-blanks
ignore leading blanks
-d, --dictionary-order
consider only blanks and alphanumeric characters
-c, --check, --check=diagnose-first
check for sorted input; do not sort
-t, char
使用单个字符char作为默认的字段分割字符
-K a.b,c.d 表示从第a.b个字段开始比较到c.d
od 用ascii和8进制码来显示
2、字段排序
ex
反向UID排序
sort -t: -k3nr /etc/passwd
ex
以GID与UID排序
sort -t: -k4n -k3n /etc/passwd
ex
以唯一的GID排序
sort -t: -k4n -u /etc/passwd -u的好处是输出唯一的记录
3、文本块排序
这种情况下没有键值可以供-k来使用,所以得提供一些额外标记
木有看懂啊。。。。就是先做一些标记。。
4、删除重复
可以利用 uniq
sort example | uniq 显示唯一的
-c计数唯一的
-d显示重复的
-u显示唯一的
uniq可以哪来跟diff工具一起使用
5、重新格式化段落
fmt指令
ex
sed -n -e 9995,10004p /usr/share/dict/words | fmt -w 30
sed -n -e 9995,10004p /usr/share/dict/words | fmt
fmt -s -w 10 仅重新格式化长的行 -s指令控制
6、计算行数,字数和字符数
wc
-c, --bytes
print the byte counts
-m, --chars
print the character counts
-l, --lines
print the newline counts
-w, --words
print the word counts
7、提取开头或结尾数行
开头:
head -n
awk 'FNR<=n'
sed -e nq
sed nq
结尾
tail -n
8、其他值得注意的工具
dd 块大小拷贝工具
file 识别文件类型
od 八进制转储
strings