Skip to content
Advertisement

dynamic string search in shell script

I have a string in shell script which is

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"

I need to find DS_BLS_max(sequence number).dat

here DS_BLS_max(sequence number).dat=DS_BLS_739.dat

Advertisement

Answer

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

Output:

DS_BLS_739.dat

See: The Stack Overflow Regular Expressions FAQ

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement