写shell时,要去掉一些不要的字符,我们经常使用 sed 's/字符//g'。当遇到如下情况,即去掉“/export/home/dw_adm/inbound/stg_items_ended_”与“_ff.dat ”,只保留“caty[0-9 ][0-9]”和后面一列的数字,我们一般用两次sed,即sed "s///.*stg_items_ended_//g" | sed "s/_ff.dat//g"。确实有了/()/,我们可以只用一次sed,sed's///.*ended_/(.*/)_ff.dat//1/g',其中/1代表了/(与/)之间所含的字符串。
/export/home/dw_adm/inbound/stg_items_ended_caty10_ff.dat 1705614049
/export/home/dw_adm/inbound/stg_items_ended_caty11_ff.dat* 2351405846
/export/home/dw_adm/inbound/stg_items_ended_caty12_ff.dat* 2228528361
/export/home/dw_adm/inbound/stg_items_ended_caty13_ff.dat* 2054387895
/export/home/dw_adm/inbound/stg_items_ended_caty14_ff.dat* 1696955787
/export/home/dw_adm/inbound/stg_items_ended_caty15_ff.dat* 2025399458
/export/home/dw_adm/inbound/stg_items_ended_caty16_ff.dat* 1852423497
/export/home/dw_adm/inbound/stg_items_ended_caty17_ff.dat* 1744840380
/export/home/dw_adm/inbound/stg_items_ended_caty18_ff.dat* 1793934887
/export/home/dw_adm/inbound/stg_items_ended_caty19_ff.dat 1695321835
/export/home/dw_adm/inbound/stg_items_ended_caty1_ff.dat 1916514122
/export/home/dw_adm/inbound/stg_items_ended_caty20_ff.dat* 1809569313
/export/home/dw_adm/inbound/stg_items_ended_caty21_ff.dat 1494150473
/export/home/dw_adm/inbound/stg_items_ended_caty22_ff.dat 1657094329
/export/home/dw_adm/inbound/stg_items_ended_caty23_ff.dat 1576093204
/export/home/dw_adm/inbound/stg_items_ended_caty24_ff.dat 1623729303
/export/home/dw_adm/inbound/stg_items_ended_caty25_ff.dat 1167637425