学习Linux命令之 wc cut

#wc  -[cmlLw]

选项和参数

       -c, --bytes

              统计字节数

       -m, --chars

              统计字符数

       -l, --lines

             统计行数

       -L, --max-line-length

              最长行的字符数

       -w, --words

              统计单词数

例子:

root@localhost:~/shell# cat file

Massachusetts

Virginia

Tulsa

Falls

Massachusetts

Virginia

View

Massachusetts

view


root@localhost:~/shell# wc -c file 

82 file

root@localhost:~/shell# wc -m file 

82 file

root@localhost:~/shell# wc -L file 

13 file

root@localhost:~/shell# wc -w file 

9 file


#cut  -[cdf]

       -c n-m

              选择从开头算起的n-m个字符

       -d '分隔符'

              以'分隔符'为标记将行分隔为一个个字段(域)

        -f N

                和-d选项一起用,选定第N个字段(域)


例子:

root@localhost:~/shell# cat test 

View Bayshore 334

Massachusetts 6th 73


#-c选项指定的范围有三种:N,只取第N个字符; N-,第N个字符开始到行末尾; N-M,第N个字符到第M个字符间的所有字符

root@localhost:~/shell# cat test | cut -c 2

i

a

root@localhost:~/shell# cat test | cut -c 2-

iew Bayshore 334

assachusetts 6th 73

root@localhost:~/shell# cat test | cut -c 2-3

ie

as


#-d ' ', 以空格作为分隔符将每一行分隔为3个字段(域); -f N, 选取第N个域的字段

root@localhost:~/shell# cat test | cut -d ' ' -f 1

View

Massachusetts

root@localhost:~/shell# cat test | cut -d ' ' -f 2

Bayshore

6th




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章