caj*_*110 5 bash grep sed wget pipe
我需要从http://en.wikipedia.org/wiki/Meme下载所有页面链接,并使用一个命令将它们保存到一个文件中.
第一次使用命令行,所以我不确定要使用的确切命令,标志等.我只知道要做什么,不得不四处寻找href意味着什么.
wget http://en.wikipedia.org/wiki/Meme -O links.txt | grep 'href=".*"' | sed -e 's/^.*href=".*".*$/\1/'
Run Code Online (Sandbox Code Playgroud)
文件中链接的输出不需要采用任何特定格式.
使用 gnu grep:
grep -Po '(?<=href=")[^"]*' links.txt
Run Code Online (Sandbox Code Playgroud)
或使用 wget
wget http://en.wikipedia.org/wiki/Meme -q -O - |grep -Po '(?<=href=")[^"]*'
Run Code Online (Sandbox Code Playgroud)