bash - trouble splitting a string by line and colon -


i know how split string such colon using ifs. however, script writing, running command returns me in format of

birthday      :      mon, date, year first day     :      mon, date, year 

i want date of birthday. in order that, doing:

ifs=: read -r -a datearr <<< "$dates" echo "${datearr[1]}"  

which ideally print date comes after "birthday :", unfortunately nothing printing. tips? should split string line well?

the expected output i'd is: mon, date, year (corresponding birthday field)

this tailor made job awk custom field separator:

awk -f '[[:blank:]]*:[[:blank:]]*' '{print $2}' file  mon, date, year mon, date, year 

note ifs=:, string left padded spaces:

while ifs=: read -r -a datearr; echo "${datearr[1]}"; done < file        mon, date, year       mon, date, year 

you can use remove spaces:

while ifs=: read -r -a datearr; echo "${datearr[1]//[[:blank:]]}"; done < file  mon,date,year mon,date,year 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -