使用通过 grep 命令获取的行号数组,我试图增加行号并使用 sed 命令检索新行号上的内容,但我假设我的语法有问题(特别是sed 部分,因为其他一切都有效。)
脚本内容如下:
#!/bin/bash
#getting array of initial line numbers
temp=(`egrep -o -n '\<a class\=\"feed\-video\-title title yt\-uix\-contextlink yt\-uix\-sessionlink secondary"' index.html |cut -f1 -d:`)
new=( )
#looping through array, increasing the line number, and attempting to add the
#sed result to a new array
for x in ${temp[@]}; do
((x=x+5))
z=sed '"${x}"q;d' index.html
new=( ${new[@]} $z )
done
#comparing the two arrays
echo ${temp[@]}
echo ${new[@]}