[英]How to replace specific section of text in a file, with text from url in bash?
[英]How to replace specific lines in a text file
我有一個這樣的文本文件。
...
# xxx start
...
# xxx end
...
我要替換# xxx start
和# xxx end
之間的行。 如果# xxx start
沒有出現,追加# xxx start
和# xxx end
在文件的結尾。
有什么辦法可以用殼嗎?
只需用sed刪除# xxx start
和# xxx end
之間的行。 然后將其附加在文件末尾。 謝謝@Barmar。
#!/bin/bash
sed -i '/# xxx start/,/# xxx end/d' file
echo '# xxx start' >> file
curl url >> file
echo '# xxx end'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.