使用 xargs 时将文本行从输入复制到输出文件
Copy line of text from input to output file while using xargs
我有一个有效的 shell 脚本,它读取一个包含 URL 的文本文件,每个文本文件单独一行。 URLs 从文件中并行读取并检查其状态代码,其中响应写入 status-codes.csv.
如何将url-list.txt引用的原始URL写到status-codes.csv输出的第一列?
状态-codes.sh
#!/bin/bash
xargs -n1 -P 10 curl -u user:pass -L -o /dev/null --silent --head --write-out '%{url_effective},%{http_code},%{num_redirects}\n' < url-list.txt | tee status-codes.csv
url-list.txt
http://website-url.com/path-to-page-1
http://website-url.com/path-to-page-2
http://website-url.com/path-to-page-3
status-codes.csv(当前输出)
http://website-url.com/path-to-page-2,200,1
http://website-url.com/path-to-page-after-any-redirects,200,2
http://website-url.com/404,404,2
status-codes.csv (期望的输出)
http://website-url.com/path-to-page-2,http://website-url.com/path-to-page-2,200,1
http://website-url.com/path-to-page-1,http://website-url.com/path-to-page-after-any-redirects,200,2
http://website-url.com/path-to-page-3,http://website-url.com/404,404,2
使用-I
选项。例如:
xargs -n1 -P 10 -I '{}' curl -u user:pass -L -o /dev/null --silent --head --write-out '{},%{url_effective},%{http_code},%{num_redirects}\n' '{}' < url-list.txt | tee status-codes.csv
man xargs
:
-I replace-str
Replace occurrences of replace-str in the initial-arguments with names read from standard input.
我有一个有效的 shell 脚本,它读取一个包含 URL 的文本文件,每个文本文件单独一行。 URLs 从文件中并行读取并检查其状态代码,其中响应写入 status-codes.csv.
如何将url-list.txt引用的原始URL写到status-codes.csv输出的第一列?
状态-codes.sh
#!/bin/bash
xargs -n1 -P 10 curl -u user:pass -L -o /dev/null --silent --head --write-out '%{url_effective},%{http_code},%{num_redirects}\n' < url-list.txt | tee status-codes.csv
url-list.txt
http://website-url.com/path-to-page-1
http://website-url.com/path-to-page-2
http://website-url.com/path-to-page-3
status-codes.csv(当前输出)
http://website-url.com/path-to-page-2,200,1
http://website-url.com/path-to-page-after-any-redirects,200,2
http://website-url.com/404,404,2
status-codes.csv (期望的输出)
http://website-url.com/path-to-page-2,http://website-url.com/path-to-page-2,200,1
http://website-url.com/path-to-page-1,http://website-url.com/path-to-page-after-any-redirects,200,2
http://website-url.com/path-to-page-3,http://website-url.com/404,404,2
使用-I
选项。例如:
xargs -n1 -P 10 -I '{}' curl -u user:pass -L -o /dev/null --silent --head --write-out '{},%{url_effective},%{http_code},%{num_redirects}\n' '{}' < url-list.txt | tee status-codes.csv
man xargs
:
-I replace-str Replace occurrences of replace-str in the initial-arguments with names read from standard input.