shell程式設計之cut

2021-09-25 22:37:59 字數 808 閱讀 2820

cut的工作就是「剪」,具體的說就是在檔案中負責剪下資料用的。cut 命令從檔案的每一行剪下位元組、字元和字段並將這些位元組、字元和字段輸出。

1.基本用法

cut [選項引數]  filename

說明:預設分隔符是製表符

2.選項引數說明

表1-55

選項引數

功能-f

列號,提取第幾列

-d分隔符,按照指定分隔符分割列

3.示例

[root@eshop-detail03 shell]# vi cut.txt

dong shen

guan zhen

wo  wo

lai  lai

le  le~~

"cut.txt" [new] 5l, 43c written

[root@eshop-detail03 shell]#  cut -d " " -f 1 cut.txt

dong

guan

wolai

le[root@eshop-detail03 shell]#  cut -d " " -f 2,3 cut.txt 

shen

zhen

wolai

le[root@eshop-detail03 shell]#  cut -d " " -f 2,3 cut.txt 

shen

zhen

wolai

le[root@eshop-detail03 shell]# cat cut.txt | grep "guan" | cut -d " " -f 1

guan 

shell程式設計之chown

語法 chown option owner group file chown option reference rfile file 描述 chown 改變指定檔案的使用者和 或組的擁有者。例如 liujl liujl rev 1 0 mycode test ls l 總用量 0 rw rw r 1...

shell 程式設計之echo

echo it is a test echo itis a testecho it is a test read 命令從標準輸入中讀取一行,並把輸入行的每個欄位的值指定給 shell 變數 bin sh read name echo name it is a test 以上 儲存為 test.sh,...

shell 程式設計之2 1

經常可以在一些指令碼,尤其是在crontab呼叫時發現如下形式的命令呼叫 tmp test.sh tmp test.log 2 1 前半部分 tmp test.sh tmp test.log很容易理解,那麼後面的2 1是怎麼回事呢?要解釋這個問題,還是得提到檔案重定向。我們知道 和 是檔案重定向符。...