shell - Extract Information From File Name in Bash -


this question has answer here:

suppose have file name abc_de_fghi_10_jk_lmn.csv. want extract id file-name i.e. 10 of id position , file-name separator. have following 2 inputs

file-name_id_position=4; [since 10 @ fourth position in file-name] file-name_delimiter="_"; 

here id can numeric or alpha-numeric. how extract 10 above file of above 2 inputs. how achieve in bash?

instead of writing regex in bash, awk:

echo 'abc_de_fghi_10_jk_lmn.csv' | awk -f_ -v pos=4 '{print $pos}' 

or if want dot delimiter (requires gnu awk):

echo 'abc_de_fghi_10_jk_lmn.csv' | awk -f'[_.]' -v pos=4 '{print $pos}' 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -