I wrote the following code to read a file and write it in a list using bash script:
index=0
while read line
do
array[$index]="$line"
index=$(($index+1))
done < ../../file.xml
However, I only need to write lines into the array if they contain the word "icon". An array element should look like this:
<icon height="36" width="36" density="ldpi" src="res/icon/android/ldpi.png"/>
Could anyone help me to fix this problem?
arr=($(grep -w 'icon' ../../file.xml))?readarray arr < <(grep -w 'icon' ../../file.xml)