我一直在试图创建一个简单的脚本,将采取查询列表从一个.txt文件,追加的主URL变量,然后刮的内容并把它输出到一个文本文件中.
这是我到目前为止所拥有的:
#!/bin/bash
url="example.com/?q="
for i in $(cat query.txt); do
content=$(curl -o $url $i)
echo $url $i
echo $content >> output.txt
done
Run Code Online (Sandbox Code Playgroud)
列表:
images
news
stuff
other
Run Code Online (Sandbox Code Playgroud)
错误日志:
curl: (6) Could not resolve host: other; nodename nor servname provided, or not known
example.com/?q= other
Run Code Online (Sandbox Code Playgroud)
如果我直接从命令行使用此命令,我会在文件中输出一些内容:
curl -L http://example.com/?q=other >> output.txt
Run Code Online (Sandbox Code Playgroud)
最终我希望输出为:
fetched: http://example.com/?q=other
content: the output of the page
followed by the next query in the list.
Run Code Online (Sandbox Code Playgroud) 我正在尝试进行递归grep搜索,例如:
grep -r -c "foo" /some/directory
Run Code Online (Sandbox Code Playgroud)
这给我输出auch为:
/some/directory/somefile_2013-04-08.txt:0
/some/directory/somefile_2013-04-09.txt:1
/some/directory/somefile_2013-04-10.txt:4
...etc
Run Code Online (Sandbox Code Playgroud)
但是,我想获得所有文件中的匹配总数,例如:
Total matches: 5
Run Code Online (Sandbox Code Playgroud)
我已经玩了一些其他的例子,比如在这个帖子中,虽然我似乎无法做到应该如此简单的事情.