I'm trying to create a char array by using split, it works so far.
The problem is when any character in the input string is preceded by \ . What happens is \ doesn't get considered as a char as it escapes the following character and gets lost, not being considered in the array.
The goal is to store everything in charArray for later use.
function getLineChars {
l=1
for line in ${fileLinesArray[@]}; do
charArray=$(echo | awk -v str="${line}" '{
split(str, lineChars, "")
for (i=1; i<=length(str); i++) {
printf("%s ", lineChars[i])
}
}')
l=$(($l+1))
echo "${charArray[@]}"
done
}
So mainly every special or strange character is getting printed into the array, except for this kind of situation:
3\zKhj awk: warning: escape sequence `\z' treated as plain `z'
and the array comes out as:
3 z K h j
Lacking the \ character, which is desired to be included in the array.
What can be done about this? Is it ok to try and use awk, or would you suggest something different?
Thanks in advance.