示例代码:
$ aa=$(xidel -se '//span[@class="random"]' 'https://www.example.com')
$ echo $aa
假设 xidel 的结果如下所示:
a abc
a sdf
a wef
a vda
a gdr
并且...假设我们想a
在这种情况下从这个列表的每个单词中删除所有的,不限于仅排除a
.
我们可以使用For Loop
这样的公式:
#"a " is the one we want to remove, so make variable for this prefix
a="a "
for ((n=-1;n>=-5;n--))
do
#process the extraction by selecting which line first
bb=$(echo "$aa" | head $n | tail -1)
#then remove the prefix after that
bb=${aa/#$a}
echo $bb
done
这将打印:
abc
sdf
wef
vda
gdr
奖金
#"a " is the one we want to remove, so make variable for this prefix
a="a "
for ((n=-1;n>=-5;n--))
do
#process the extraction by selecting which line first
bb=$(echo "$aa" | head $n | tail -1)
#then remove the prefix after that
bb=${aa/#$a}
#echo everything except 2nd line
if [ $n != -2 ] ; then
echo $bb
fi
done
这将打印:
abc
wef
vda
gdr
欢迎任何其他输入