Пример кода:
$ 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
Любой другой ввод приветствуется