文本操作

cat、tac、od 和 split

cat:显示文件

tac:与cat相反的顺序显示一个文件

od:转储

split:文件分割

wc、head 和 tail

使用 expand 和 unexpand





[ian@echidna lpi103]$ expand -t 1 text2

9 plum

3 banana

10 apple

[ian@echidna lpi103]$ expand -t8 text2|unexpand -a -t2|expand -t3

9 plum

3 banana

10 apple

使用 tr





[ian@echidna lpi103]$ cat text1 |tr ' ' '"t'|cat - text2

1 apple

2 pear

3 banana

9 plum

3 banana

10 apple

 

pr、nl 和 fmt

pr 命令用于对文件进行格式化以便打印。默认的页眉包括文件名、创建文件的日期和时间以及页号,页脚是两个空行。当从多个文件或标准输入流创建输出时,当前日期和时间替代文件名和创建日期。可以通过选项分栏并列打印文件并控制格式化的许多方面。详情请参考手册页。

nl 命令对行进行编号,这在打印文件时很方便。还可以用 cat 命令的 -n 选项对行进行编号。清单 31 显示如何打印 text1,然后给 text2 加行号并将它打印在 text1 旁边。

eg:

[ian@echidna lpi103]$ nl text2 | pr -m - text1 | head

2005-09-26 11:48 Page 1

1 9 plum 1 apple

2 3 banana 2 pear

3 10 apple 3 banana

 

字符和数字式排序

示例对第一个字段进行数字式排序,对第二个字段按照整理序列(字母表次序)排序。它还演示了使用 -u 选项消除任何重复的行,只保留独特的行。

[ian@echidna lpi103]$ cat text1|tr ' ' '"t'|sort -u -k1n -k2 - text2

posted @ 2008-08-18 15:36  xiaoyixy  阅读(192)  评论(0编辑  收藏  举报