当前位置: 技术问答>linux和unix
文件名称如何分段获取
来源: 互联网 发布时间:2017-05-30
本文导语: 有一些日志文件如下,有与位数不固定,如何分段获取每个_之间的数据,如只获取1090085518,或只获取11beta9 1090085518_2014_10_06_65_11beta9_4936_wt1_04_18_52.log 1090085518_2014_10_06_65_11beta9_4942_wt1_18_11_10.log 1122872944_2014_09_24_65_11beta9...
有一些日志文件如下,有与位数不固定,如何分段获取每个_之间的数据,如只获取1090085518,或只获取11beta9
1090085518_2014_10_06_65_11beta9_4936_wt1_04_18_52.log
1090085518_2014_10_06_65_11beta9_4942_wt1_18_11_10.log
1122872944_2014_09_24_65_11beta9_4908_wt1_07_14_56.log
1122872944_2014_09_26_65_11beta9_4912_wt1_06_27_48.log
1122872944_2014_10_08_65_11beta9_4936_wt1_07_27_08.log
1122872944_2014_10_09_65_11beta9_4938_wt1_07_09_35.log
1122872944_2014_10_10_65_11beta9_4940_wt1_06_35_54.log
1122872944_2014_10_11_65_11beta9_4942_wt1_07_29_48.log
113550045_2014_09_23_65_11beta9_4907_wt1_12_20_03.log
113550045_2014_09_24_65_11beta9_4908_wt1_07_28_13.log
113550045_2014_09_24_65_11beta9_4909_wt1_17_09_02.log
113550045_2014_09_25_65_11beta9_4910_wt1_06_24_43.log
113550045_2014_09_25_65_11beta9_4911_wt1_12_47_11.log
1090085518_2014_10_06_65_11beta9_4936_wt1_04_18_52.log
1090085518_2014_10_06_65_11beta9_4942_wt1_18_11_10.log
1122872944_2014_09_24_65_11beta9_4908_wt1_07_14_56.log
1122872944_2014_09_26_65_11beta9_4912_wt1_06_27_48.log
1122872944_2014_10_08_65_11beta9_4936_wt1_07_27_08.log
1122872944_2014_10_09_65_11beta9_4938_wt1_07_09_35.log
1122872944_2014_10_10_65_11beta9_4940_wt1_06_35_54.log
1122872944_2014_10_11_65_11beta9_4942_wt1_07_29_48.log
113550045_2014_09_23_65_11beta9_4907_wt1_12_20_03.log
113550045_2014_09_24_65_11beta9_4908_wt1_07_28_13.log
113550045_2014_09_24_65_11beta9_4909_wt1_17_09_02.log
113550045_2014_09_25_65_11beta9_4910_wt1_06_24_43.log
113550045_2014_09_25_65_11beta9_4911_wt1_12_47_11.log
|
如果格式固定,也可以用cut
$echo 1090085518_2014_10_06_65_11beta9_4936_wt1_04_18_52.log|cut -d_ -f1
1090085518
$echo 1090085518_2014_10_06_65_11beta9_4936_wt1_04_18_52.log|cut -d_ -f6
11beta9
$echo 1090085518_2014_10_06_65_11beta9_4936_wt1_04_18_52.log|cut -d_ -f1
1090085518
$echo 1090085518_2014_10_06_65_11beta9_4936_wt1_04_18_52.log|cut -d_ -f6
11beta9