cut 用于取域
-c选项
cut -cchars file
cut -c3,5,6 file
cut -c5-10 file
-d选项
分割符
-f选项
取域
cut -ddchar –ffields file
$ cut -d: -f1 /etc/passwd Extract field 1
$ cut -d: -f1,6 /etc/passwd Extract fields 1 and 6
sed -n l file
查看文件分割符号
paste
paste和cut相反,是合并文件
paste files
$ cat names
Tony
Emanuel
Lucy
Ralph
Fred
$ cat numbers
(307) 555-5356
(212) 555-3456
(212) 555-9959
(212) 555-7741
(212) 555-0040
$ paste names numbers
Tony (307) 555-5356
Emanuel (212) 555-3456
Lucy (212) 555-9959
Ralph (212) 555-7741
Fred (212) 555-0040
$ cat address
55-23 Vine Street, Miami
39 University Place, New York
17 E. 25th Street, New York
38 Chauncey St., Bensonhurst
17 E. 25th Street, New York
$ paste names addresses numbers
-d选项
如果不想使用tab作为域分隔符,可以使用-d来指定
-dchars
$ paste -d'+' names addresses numbers
Tony+55-23 Vine Street, Miami+(307) 555-5356
Emanuel+39 University Place, New York+(212) 555-3456
Lucy+17 E. 25th Street, New York+(212) 555-9959
Ralph+38 Chauncey St., Bensonhurst+(212) 555-7741
Fred+17 E. 25th Street, New York+(212) 555-0040
-s选项
合并来自同一个文件中的行
$ paste -s names Paste all lines from names
Tony Emanuel Lucy Ralph Fred
$ ls | paste -d' ' -s - Paste ls's output, use space as delimiter
tr
tr from-chars to-chars
$ tr e x < intro
将intro中e转换成x
$ cat /etc/passwd | tr : ' '
转换:为空
$ date | tr ' ' '\12'
转换空格为换行
tr转换一个范围
$ tr '[a-z]' '[A-Z]' < intro
小写转换成大写
$ tr '[A-Z]' '[a-z]' < intro
-s选项
$ cat lotsaspaces
This is an example of a
file that contains a lot
of blank spaces.
$ tr –s ' ' ' ' < lotsaspaces
This is an example of a
file that contains a lot
of blank spaces.
挤掉多个空格
-d选项
tr -d from-chars
删除字符
阅读(978) | 评论(0) | 转发(0) |