while read line do done < file

zzx@zzx120:~/test1$ cat file.txt   
11
22
zzx@zzx120:~/test1$ cat ./read.sh
#!/bin/bash
while read line
do
#echo "hello"
echo $line
done < file.txt
zzx@zzx120:~/test1$ ./read.sh
11
22

 

 百度上使用site inurl语法查询,输入site:www.baidu.com inurl:news,则会搜出所有在www.baidu.com

  站点上的包含"news"子串的url.

   现在有两份数据:一份是site_inurl.txt,一份是url.txt.其中,site_inurl.txt中每一行是一个site

   inurl 语法组成的查询串,url.txt保存的是url列表.

      在url列表中找出所有能被site_inurl.txt中查询串检索到的url

      如:site中inurl.txt内容如下:

             site:www.baidu.com inurl:/more

             site:zhidao.baidu.com inurl:/browse/

             site:www.sina.com.cn inurl:www20041223am

       url.txt内容如下:

            http://www.baidu.com/more/

            http://www.baidu.com/guding/more.html

            http://www.baidu.com/events/20060105/photomore.html

            http://hi.baidu.com/browse/

            http://hi.baidu.com/baidu/

            http://www.sina.com.cn/head/www20021123am.html

            http://www.sina.com.cn/head/www20041223am.html

      则你的程序运行结果应该为:

            http://www.baidu.com/more/

            http://www.baidu.com/guding/more.html

            http://www.sina.com.cn/head/www20041223am.html

      shell程序:

                   #!/bin/bash

                   #file.sh

                   while read -r line

                   do

                      set $(echo $line|awk -F"[: ]" '{print $2,$4}')

                      grep "$1.$2" url.txt   #用inurl.txt中的关键字在url.txt中查找

                   done < inurl.txt

      注意公式:

                  echo "forum-45-85.html|cut -d- -f3|cut -d. -f1

 

转载于:https://www.cnblogs.com/hanxing/p/4226434.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值