shell文本行截取子串

1、格式化的文本內容

# head 2620.log
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:12:37,902 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/PRMSL/18082620.084"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:12:40,683 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/TMP_CHANGE_24H/850/18082620.087"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:12:41,326 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/PRMSL_CHANGE_24H/18082620.084"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:14:13,859 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/TMP/925/18082620.090"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:14:13,987 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/HGT/925/18082620.090"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:14:14,238 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/RH/925/18082620.087"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:14:14,238 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/RH/925/18082620.084"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:14:14,361 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/SPFH/925/18082620.087"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:14:14,639 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/VVEL_GEOMETRIC/925/18082620.087"
logs/mdfs-monitor.nwp.py.log.10:2018-08-27 01:14:15,221 - root - INFO - rpush "filename:/nwp" "cassandra:/GRAPES_GFS/TMP/850/18082620.090"

2、從指定位置開始截取

# cut -c 72- 2620.log | head
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/PRMSL/18082620.084"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/TMP_CHANGE_24H/850/18082620.087"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/PRMSL_CHANGE_24H/18082620.084"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/TMP/925/18082620.090"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/HGT/925/18082620.090"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/RH/925/18082620.087"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/RH/925/18082620.084"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/SPFH/925/18082620.087"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/VVEL_GEOMETRIC/925/18082620.087"
rpush "filename:/nwp" "cassandra:/GRAPES_GFS/TMP/850/18082620.090"

3、截取參數說明

# cut --help
用法:cut [選項]... [文件]...
Print selected parts of lines from each FILE to standard output.

Mandatory arguments to long options are mandatory for short options too.
-b, --bytes=列表 只選中指定的這些字節
-c, --characters=列表 只選中指定的這些字符
-d, --delimiter=分界符 使用指定分界符代替製表符作爲區域分界
-f, --fields=LIST select only these fields; also print any line
that contains no delimiter character, unless
the -s option is specified
-n with -b: don't split multibyte characters
--complement 補全選中的字節、字符或域
-s, --only-delimited 不打印沒有包含分界符的行
--output-delimiter=字符串 使用指定的字符串作爲輸出分界符,默認採用輸入
的分界符
--help 顯示此幫助信息並退出
--version 顯示版本信息並退出

僅使用f -b, -c 或-f 中的一個。每一個列表都是專門爲一個類別作出的,或者您可以用逗號隔
開要同時顯示的不同類別。您的輸入順序將作爲讀取順序,每個僅能輸入一次。
每種參數格式表示範圍如下:
N 從第1 個開始數的第N 個字節、字符或域
N- 從第N 個開始到所在行結束的所有字符、字節或域
N-M 從第N 個開始到第M 個之間(包括第M 個)的所有字符、字節或域
-M 從第1 個開始到第M 個之間(包括第M 個)的所有字符、字節或域

當沒有文件參數,或者文件不存在時,從標準輸入讀取

GNU coreutils online help: <http://www.gnu.org/software/coreutils/&gt;
請向<http://translationproject.org/team/zh_CN.html&gt; 報告cut 的翻譯錯誤
要獲取完整文檔,請運行:info coreutils 'cut invocation'

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