gpt4 book ai didi

linux - 使用 bash 脚本遍历包含域的文本文件

转载 作者:IT王子 更新时间:2023-10-29 00:50:45 30 4
gpt4 key购买 nike

我写了一个脚本来读取网页的 href 标签并获取该网页上的链接并将它们写入文本文件。现在我有一个包含链接的文本文件,例如:

http://news.bbc.co.uk/2/hi/health/default.stm
http://news.bbc.co.uk/weather/
http://news.bbc.co.uk/weather/forecast/8?area=London
http://newsvote.bbc.co.uk/1/shared/fds/hi/business/market_data/overview/default.stm
http://purl.org/dc/terms/
http://static.bbci.co.uk/bbcdotcom/0.3.131/style/3pt_ads.css
http://static.bbci.co.uk/frameworks/barlesque/2.8.7/desktop/3.5/style/main.css
http://static.bbci.co.uk/frameworks/pulsesurvey/0.7.0/style/pulse.css
http://static.bbci.co.uk/wwhomepage-3.5/1.0.48/css/bundles/ie6.css
http://static.bbci.co.uk/wwhomepage-3.5/1.0.48/css/bundles/ie7.css
http://static.bbci.co.uk/wwhomepage-3.5/1.0.48/css/bundles/ie8.css
http://static.bbci.co.uk/wwhomepage-3.5/1.0.48/css/bundles/main.css
http://static.bbci.co.uk/wwhomepage-3.5/1.0.48/img/iphone.png
http://www.bbcamerica.com/
http://www.bbc.com/future
http://www.bbc.com/future/
http://www.bbc.com/future/story/20120719-how-to-land-on-mars
http://www.bbc.com/future/story/20120719-road-opens-for-connected-cars
http://www.bbc.com/future/story/20120724-in-search-of-aliens
http://www.bbc.com/news/

我希望能够过滤它们,以便返回如下内容:

http://www.bbc.com : 6
http://static.bbci.co.uk: 15

旁边的值表示域在文件中出现的次数。考虑到我会有一个循环遍历文件,我怎样才能在 bash 中实现这一点。我是 bash shell 脚本的新手?

最佳答案

$ cut -d/ -f-3 urls.txt | sort | uniq -c                  
3 http://news.bbc.co.uk
1 http://newsvote.bbc.co.uk
1 http://purl.org
8 http://static.bbci.co.uk
1 http://www.bbcamerica.com
6 http://www.bbc.com

关于linux - 使用 bash 脚本遍历包含域的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11644399/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com