We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Remove the First Capital Letter from Each Element
Remove the First Capital Letter from Each Element
Sort by
recency
|
178 Discussions
|
Please Login in order to post a comment
!/bin/bash
countries=() while IFS= read -r line; do # Replace first uppercase letter with '.' transformed=line" | sed 's/[A-Z]/./') countries+=("$transformed") done
Print all transformed country names separated by spaces
echo "${countries[@]}"
Great challenge on HackerRank! š§ Working with arrays in Bash really sharpens your scripting skills, and manipulating stringsālike removing the first capital letter from each elementāadds an extra layer of complexity. Mahadevbook777 ID
readarray list echo ${list[@]/[A-Z]/.}
readarray -t a arr={arr[@]}"
This function modifies a list by converting the first capital letter of each element to lowercase. It ensures uniform formatting while preserving the rest of the string. Ekbet16