學習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




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