Shell脚本中的动态字符串搜索

时间:2018-08-24 14:53:51

标签: regex linux bash shell

我在shell脚本中有一个字符串

list="apr/2018-06-24 17_10_39/2018-06-24 17_10_39.html 

 apr/2018-06-24 17_10_39/access_log.zip

 apr/2018-06-25 17_12_48/2018-06-25 17_12_48.html

 apr/2018-06-25 17_12_48/access_log.zip

 apr/2018-06-26 17_13_36/2018-06-26 17_13_36.html

  DS_BLS_731.dat

 DS_BLS_732.dat

 DS_BLS_733.dat

 apr/2018-06-26 17_13_37/ DS_BLS_739.dat

 apr/2018-06-26 17_13_38/ DS_BLS_738.dat

 apr/2018-06-26 17_13_39/ DS_BLS_737.dat"

我需要找到DS_BLS_max(序列号).dat

此处DS_BLS_max(序列号).dat = DS_BLS_739.dat

1 个答案:

答案 0 :(得分:0)

grep -o 'DS_BLS_[0-9]*\.dat' <<< "$list" | sort -V | tail -n 1

输出:

DS_BLS_739.dat

请参阅:MySQL official site