问题描述
我有一个的wget
命名脚本 Chktitle.sh
- 该脚本的命令如下图所示。
$ Chktitle.sh我的网址
然后我有一个文件名为 url.txt
有超过100线,URL和IPS检查网页的标题。
然后,我有 RESULTS.TXT
作为一个空白文件。
有没有什么办法可以对文件中的每一行类似下面执行重复动作:
从url.txt抢行1
-----
然后执行Chktitle.sh一号线
-----
现在保存在RESULTS.TXT一号线的结果
-----
现在后藤2号线........
等等等等
我要确保它不仅将previous一个人完成后,执行下一行。
任何一个可以告诉我执行此没有简单的方法?我很高兴地用Perl,sh和考虑其他语言。
中的内容 chktitle.sh
:
#!/斌/庆典
字符串= $ 1/搜索/
wget的--quiet -O - $字符串\\
| SED -n -e'!;标题>(* \\)\\< /标题> S * LT。!* \\ 1 p'
也许这样的事情可以帮助(前提是我理解正确):
而读线;做
/path/to/Chktitle.sh X$行>> RESULTS.TXT;
完成< /path/to/input.txt
对于 /path/to/input.txt
的每一行,执行你的脚本,并附加输出(>>
),以 RESULTS.TXT
。
当然,你总是可以添加其他语句在while循环:
而读线;做
#初始化VAR来chktitle输出
VAR = $(/路径/要/ Chktitle.sh X$行); #添加条件
如果[$ VAR=谷歌];然后
回声谷歌>>的Result.txt;
其他
回声没有谷歌>>的Result.txt;
科幻
完成< /path/to/input.txt
I have a wget
script named Chktitle.sh
-- this script takes a command like below
$ Chktitle.sh "my url"
I then have a file name url.txt
with over 100 lines with urls and ips to check for web-page titles.Then i have results.txt
as a blank file.
Is there any way I can perform a repetitive action like below for each line in the file:
Grab line1 from url.txt
-----
then execute Chktitle.sh "line1"
-----
Now save the result for line1 in results.txt
-----
Now goto Line2 ........
etc etc etc
I need to make sure that it will only execute the next line after the previous one has finished.Can any one show me any easy way to perform this? I am happy to use Perl, sh, and consider other languages..
The contents of chktitle.sh
:
#!/bin/bash
string=$1"/search/"
wget --quiet -O - $string \
| sed -n -e 's!.*<title>\(.*\)</title>.*!\1!p'
Maybe something like this could help (provided that I understood correctly) :
while read line; do
/path/to/Chktitle.sh x"$line" >> results.txt;
done < /path/to/input.txt
For each line in /path/to/input.txt
, execute your script and append the output (>>
) to results.txt
.
Of course you could always add additional statements in your while loop :
while read line; do
# Initialise var to output of chktitle
var=$(/path/to/Chktitle.sh x"$line");
# Add conditions
if [ "$var" = "google" ]; then
echo "google" >> result.txt;
else
echo "not google" >> result.txt;
fi
done < /path/to/input.txt
这篇关于对于每一个行文件syncronously执行命令,并保存到另一个文件的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!