小编sof*_*f31的帖子

根据域名使 URL 唯一

我有一个名为urls.list的 URL 列表:

https://target.com/?first=one
https://target.com/something/?first=one
http://target.com/dir/?first=summer
https://fake.com/?first=spring
https://example.com/about/?third=three
https://example.com/?third=three
Run Code Online (Sandbox Code Playgroud)

并且我想根据它们的域使它们独一无二,例如https://target.com,这意味着每个域及其协议都会打印一次,并且避免使用下一个 URL。所以结果是:

https://target.com/?first=one
http://target.com/dir/?first=summer
https://fake.com/?first=spring
https://example.com/about/?third=three
Run Code Online (Sandbox Code Playgroud)

这就是我试图做的:

cat urls.list | cut -d"/" -f1-3 | awk '!a[$0]++' >> host_unique.del

for urls in $(cat urls.list); do

    for hosts in $(cat host_unique.del); do
        if [[ $hosts == *"$urls"* ]]; then
            echo "$hosts"
        fi
    done
done
Run Code Online (Sandbox Code Playgroud)

bash awk unique

3
推荐指数
1
解决办法
78
查看次数

标签 统计

awk ×1

bash ×1

unique ×1