I am trying to declare an array in my shell script and then have written a for loop to access those array elements into another file. But it is only taking the first element. I've tried the below :
raw_cd=(1150 1151)
i=0
for i in "${raw_cd[@]}"
do
grep -wr "${raw_cd[@]}" file1.txt > /opt/tmp/raw.txt
echo "$i"
done
It is taking only the first element 1150 and also giving output as :-
file1.txt:|1150|
file1.txt:|1150|
file1.txt:|1150|
where am i doing wrong?
ior removei=0completelygrep -wr "$i" file1.txtinstead?> /opt/tmp/raw.txtoverwrites the file each loop. Did you mean to>> /opt/tmp/raw.txt?