From 8d24cff11b964c86732bb77bd318b7841d011d98 Mon Sep 17 00:00:00 2001 From: Wiwi Kuan Date: Wed, 17 Jul 2024 10:20:31 +0800 Subject: [PATCH] Add files via upload --- url-extract.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 url-extract.sh diff --git a/url-extract.sh b/url-extract.sh new file mode 100644 index 0000000..18b914d --- /dev/null +++ b/url-extract.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +echo "在下方貼上文字。按 Ctrl+D 結束輸入:" + +# 讀取多行輸入 +input=$(cat) + +# 使用 sed 擷取 URL +urls=$(echo "$input" | sed -En 's/.*((https?:\/\/)[^ )]*)[ )].*/\1/gp') + +# 檢查是否找到 URL +if [ -n "$urls" ]; then + echo -e "\n擷取到的 URL:" + echo "$urls" +else + echo -e "\n在輸入的文字中沒有找到 URL。" +fi