Suppose I have a file with a name ABC_DE_FGHI_10_JK_LMN.csv. I want to extract the ID from the file-name i.e. 10 with the help of ID position and file-name separator. I have following two inputs
File-name_ID_Position=4; [since 10 is at fourth position in file-name]
File-name_Delimiter="_";
Here ID can be numeric or alpha-numeric. So how extract the 10 from above file with the help of above two inputs. How to achieve this in bash?
x="ABC_DE_FGHI_10_JK_LMN.csv"; x=${x#*_*_*_}; echo ${x%_*_*}x="ABC_DE_FGHI_10.csv"; x=${x#*_*_*_}; echo ${x%_*_*}returns10.csvnot just10which he wants. However with this marked as a duplicate I guess it doesn't really matter._or.as separator:x="ABC_DE_FGHI_10.csv"; x=${x#*[_.]*[_.]*[_.]}; echo ${x%[_.]*}