I have a string in Linux shell. This string contains underscores in it.
I want to extract a substring from the string.
I want to extract the substring after the third occurrence of an underscore, counted from the end of the string.
file_name='email_Tracking_export_history_2018_08_15'
string_name="${file_name#*_*_*_}"
file_name2='email_Tracking_export_2018_08_15'
string_name2="${file_name2#*_*_*_}"
echo "$string_name"
echo "$string_name2"
The result
history_2018_08_15
2018_08_15
As you see, string_name="${file_name#*_*_*_}"
is not working properly.
Desired result:
2018_08_15
2018_08_15
How can I achieve my desired result?