У вас почти получилось с:
sed -i '/ Hello / {/ World / a} appendstring' file
Вам нужно разделить свои аргументы. Используйте -e
, например:
sed -i -e '/Hello/{/World/a appendstring' -e '}' file
Обратите внимание, что использование команды a ppend без новой строки является расширением GNU, как и переключатель -i
.
Чтобы сделать это более переносимым, а также учитывая возможность совпадения нескольких строк, попробуйте:
sed '/multiple/{/words/{/to/{/match/ s/$/append this/;};};}' file > newfile
mv newfile file
Поскольку вы уже используете GNU Sed, просто используйте:
sed -i -e '/multiple/{/words/{/to/{/match/ a append this' -e 'a and also this' -e 'a oh and this too' -e '};};}' file
Вот фрагмент, выполняющий преобразование в bash.
#!/bin/bash
# The array of results passed to rtorrent in the end
results=()
# The file listing the trackers is the first argument
trackers="$1"
shift
# create the tracker list url part.
# sed reads the file and puts '&tr=' before each line,
# then it replaces all : and / with the percent escaped version for urls.
# tr deletes all newlines (turning the text into one long line)
tracker_list_for_url="$(sed 's/^/&tr=/;s/:/%3A/g;s#/#%2F#g' < "$trackers" \
| tr -d '\n')"
# loop over arguments and add them to $results
for arg in "$@"; do
# remove the extension
hex_part="${arg%.meta}"
# append to results array
results+="magnet:?xt=urn:btih:$hex_part$tracker_list_for_url"
done
exec rtorrent "${results[@]}"
Я еще не понимаю, какая программа в вашем сценарии вызывает какую программу, и когда и как аргументы создаются и передаются другим программам. Итак, я сделал следующие предположения:
rtorrent
Если эти предположения неверны пожалуйста, поясните или используйте приведенный выше сценарий и адаптируйте его к своим потребностям.