小编Men*_*ega的帖子

Shell脚本使用curl循环遍历URL

我一直在试图创建一个简单的脚本,将采取查询列表从一个.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)

bash curl loops

21
推荐指数
2
解决办法
8万
查看次数

递归Grep仅显示总匹配计数

我正在尝试进行递归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)

我已经玩了一些其他的例子,比如在这个帖子中,虽然我似乎无法做到应该如此简单的事情.

bash shell grep

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

bash ×2

curl ×1

grep ×1

loops ×1

shell ×1