Answer the question
In order to leave comments, you need to log in
Why doesn't the for loop work?
So, I'll start over with what my script does.
There is such a .html file.
<tr>
<td>click</td>
<td>new</td>
<td>Type_Account</td>
</tr>
#!/bin/bash
cd ~/dir
line1="Type_Account"
IFS=","
array=( $line1 )
line2="pro"
IFS=","
array2=( $line2 )
line3=`ls ~/dir/ | egrep '\.html'`
for ((i=0;i<"${#array[@]}";++i)); do
for y in $line3; do
# получаем </tr> тег в переменную w. если он <tr>, это переменная
w=`grep -A 1 "<td>${array[$i]}</td>" $y | grep -v "${array[$i]}"`
# получаем содержмое переменной
w2=`grep -B 1 "<td>${array[$i]}</td>" $y | grep -v "${array[$i]}"`
# получаем номер линии содержимого переменной
number=`grep -n -B 1 "<td>${array[$i]}</td>" $y | grep -v "${array[$i]}" | cut -d "-" -f 1`
if ; then
echo "ok"
echo $w2
sed -i -e "$number s/\(<td>\).*\(<\/td>\)/<td>${array2[$i]}<\/td>/g" $y
else
echo "not ok"
fi
done
done
+ for y in $line3
++ grep -A 1 '<td>Type_Account</td>' 'index.html
index2.html'
++ grep -v Type_Account
grep: index.html
index2.html: No such file or directory
+ w=
++ grep -B 1 '<td>Type_Account</td>' 'index.html
index2.html'
++ grep -v Type_Account
grep: index.html
index2.html: No such file or directory
+ w2=
++ grep -n -B 1 '<td>Type_Account</td>' 'index.html
index2.html'
++ grep -v Type_Account
++ cut -d - -f 1
grep: index.html
index2.html: No such file or directory
+ number=
+
+ echo 'not ok'
not ok
+ (( ++i ))
+ (( i<1 ))
for y in $line3; do
index.html index2.html
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question