国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Linux Shell > 正文

linux的cut命令用法總結

2020-07-27 18:45:24
字體:
來源:轉載
供稿:網友

要用到,來mark一下:

ubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt abcabcdubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt | cut -c 1aaubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt | cut -c 2bbubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt | cut -c 1-2ababubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt | cut -c 1-3abcabcubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt | cut -c 1-4abcabcdubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt | cut -c 1-5abcabcdubuntu@VM-0-15-ubuntu:~/taoge$ cat b.txt | cut -c 1-6abcabcdubuntu@VM-0-15-ubuntu:~/taoge$ 

常常配合awk使用。

cut命令可以按字節,字符,域來截取字串,在某些情況下使用cut,確實很方便,下面簡單總結下:

1.按字符截取:(源字串:123:456:789)

1>截取第三個字符:

echo 123:456:789 | cut -c33

2>截取第三到第六之間的字符:

echo 123:456:789 | cut -c3-63:45

3>截取前三個字符

echo 123:456:789 | cut -c-3123

4>提取第三個及其后面的所有字符

echo 123:456:789 | cut -c3-3:456:789

5>提取第三到第六和第八到第十間的字符

echo 123:456:789 | cut -c3-6,8-103:45:78

小結下

>>這個“-”比較有意思,

在inx前,表示從字串投開始,

放在inx后,表示從idx開始到字串末尾,

在兩個idx之間,表示從idx1到idx2。

>>還有這個“,”可以連接我們選擇的不連續的域,

比如要取第1,3,5,7個字符: 

echo 123:456:789 | cut -c1,3,5,71346

>>對于-b選項應該和-c選項差不多吧,就是單位不同而已(我沒有像上面一樣測試,只是我的理解)

對于-d選項需要配合著-f選項使用,-d是用來指定分隔符,-f用來指定提取第幾個域的內容

echo 123:456:789 | cut -d : -f 3789

cut比較小巧,在適當的場景下使用效率很高,但是它不支持正則表達式,所以在復雜的情況下還是使用awk或者sed比較好!

[xxx@~]$ cut --helpUsage: cut OPTION... [FILE]...Print selected parts of lines from each FILE to standard output.Mandatory arguments to long options are mandatory for short options too. -b, --bytes=LIST    select only these bytes -c, --characters=LIST  select only these characters -d, --delimiter=DELIM  use DELIM instead of TAB for field delimiter -f, --fields=LIST    select only these fields; also print any line              that contains no delimiter character, unless              the -s option is specified -n           (ignored)   --complement    complement the set of selected bytes, characters              or fields -s, --only-delimited  do not print lines not containing delimiters   --output-delimiter=STRING use STRING as the output delimiter              the default is to use the input delimiter   --help   display this help and exit   --version output version information and exit

Use one, and only one of -b, -c or -f.  Each LIST is made up of one
range, or many ranges separated by commas.  Selected input is written
in the same order that it is read, and is written exactly once.
Each range is one of:

  •   N     N'th byte, character or field, counted from 1
  •   N-    from N'th byte, character or field, to end of line
  •   N-M   from N'th to M'th (included) byte, character or field
  •   -M    from first to M'th (included) byte, character or field

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林網的支持。如果你想了解更多相關內容請查看下面相關鏈接

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通江县| 历史| 中阳县| 巴楚县| 香港 | 泰州市| 固始县| 鹿邑县| 聊城市| 华容县| 大关县| 紫金县| 霍山县| 胶南市| 陆良县| 思南县| 太康县| 积石山| 沾化县| 阳春市| 高碑店市| 同江市| 益阳市| 砚山县| 彰化市| 固镇县| 禹州市| 普安县| 林周县| 庆城县| 邻水| 南昌市| 广州市| 高要市| 礼泉县| 长春市| 株洲市| 英超| 山西省| 花莲市| 兴安盟|