Hi all,
i have a data array as followes.
ARRAY[0]=DFSG345GGG
ARRAY[1]=234FDFG090
ARRAY[2]=VDFVGBGHH
so on..........
i need all english letters to be change to lower case. So i am expecting to see
ARRAY[0]=dfsg345ggg
ARRAY[1]=234fdfg090
ARRAY[2]=vdfvgbghh
so on........
If i have to copy this data in to a 2nd array to do this, i am ok. But it would be nice if i only need one array. Can someone please help me here?
by the way, i set the array as follows.
set -A array `grep -v "#" ${file}`
This is in Kshell
This is a bash example
#!/bin/bash
ARRAY[0]=DFSG345GGG
ARRAY[1]=234FDFG090
ARRAY[2]=VDFVGBGHH
x=0;while [ ${x} -lt ${#ARRAY[*]} ] ; do ARRAY[$x]=$(tr [A-Z] [a-z] <<< ${ARRAY[$x]}); let x++; done
x=0;while [ ${x} -lt ${#ARRAY[*]} ] ; do echo ${ARRAY[$x]}; let x++; done
and this is a bash 4.x only , shell only solution
#!/bin/bash
ARRAY[0]=DFSG345GGG
ARRAY[1]=234FDFG090
ARRAY[2]=VDFVGBGHH
x=0;while [ ${x} -lt ${#ARRAY[*]} ] ; do ARRAY[$x]=${ARRAY[$x],,}; let x++; done
x=0;while [ ${x} -lt ${#ARRAY[*]} ] ; do echo ${ARRAY[$x]}; let x++; done
This should do it - currently typing on a pc so can't test it...
for array in ${array[@]}
do
echo $array | tr '[:upper:]' '[:lower:]'
done
hi dingerkingh, i am using Kshell. code is giving me an error.
---------- Post updated at 06:50 PM ---------- Previous update was at 06:12 PM ----------
Hi danmero
i am getting an error.
ARRAY[$x]=${ARRAY[$x],,}; bad substitution
Did you try the first solution(change the shebang), the second solution work Only on bash 4.x
i tried both, but i still get errors. Right now code is,
set -A array `grep -v "#" ${file}`
x=0;while [ ${x} -lt ${#ARRAY[]} ] ; do ARRAY[$x]=$(tr [A-Z] [a-z] <<< ${ARRAY[$x]}); let x++; done
x=0;while [ ${x} -lt ${#ARRAY[]} ] ; do echo ${ARRAY[$x]}; let x++; done
You can try any one of these:
set -A array `tr '[A-Z]' '[a-z]' < file`
set -A array `tr '[[:upper:]]' '[[:lower:]]' < file`
edidataguy,
how do i combine your code with this?
`grep -v "#" ${file}`
guys, thank you very much. i got it to work. Thanks again.