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

while read line do done < file的更多相关文章

  1. RHEL5.X 重启网卡出现./network-functions: line 78: .: ifcfg-eth0: file not found

    错误信息: 红帽RHEL5.5系统,重启网卡报错 [root@localhost network-scripts]# service network restart Shutting down int ...

  2. MySQL_ERROR 1231 (42000) at line XX in file 'file_name' Variable 'time_zone' can't be

    类似的错误信息如下 ERROR 1231 (42000) at line 10370 in file: '/root/sql/ultrax_170322.dmp': Variable 'time_zo ...

  3. 刷题中熟悉Shell命令之Tenth Line和Transpose File [leetcode]

    首先介绍题目中要用的4个Shell命令 sed awk head tail的常用方法.(打好地基,才能建成高楼!) sed:(转自:http://www.cnblogs.com/barrychiao/ ...

  4. git报错:fatal: bad config line 1 in file C:/Users/JIANGXIAOLIANG/.gitconfig

    在给git设置用户名和邮箱的时候报下面的错误:fatal: bad config line 1 in file C:/Users/JIANGXIAOLIANG/.gitconfig看提示的意思是git ...

  5. 常规问题解决:File "/usr/bin/yum", line 30 及 File "/usr/libexec/urlgrabber-ext-down", line 28

    在执行yum命令时忽然发现出现以下报错: # yum list File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ...

  6. Go to the first line OR the last line of the file

    (1) 跳到首行 :1 或 gg (2)跳到最后一行 :$ 或 G 或shift+g(大写.当前若大小写锁定直接按g,未锁定则按shift+g)

  7. idea git pull fatal: bad config line 1 in file /.gitconfig 问题处理

    在网上搜好多都是直接改username和useremail的,但是没有说明原理. 因为我的电脑是新入职接手上一家的电脑 后来在git bash 里面用$ git config user.name 原来 ...

  8. Traceback (most recent call last): File "setup.py", line 22, in <module> execfile(join(CURDIR, 'src', 'SSHLibrary', 'version.py')) NameError: name 'execfile' is not defined

    在python3环境下安装robotframework-SSHLibraray报错: Traceback (most recent call last): File "setup.py&qu ...

  9. cat file | while read line的问题

    循环中的重定向 或许你应该在其他脚本中见过下面的这种写法: while read line do        … done < file 刚开始看到这种结构时,很难理解< file是如何 ...

随机推荐

  1. POJ3616:Milking Time

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5682   Accepted: 2372 Desc ...

  2. windowsXP下 使用live555搭建视频服务器,并使用ffplay和VLC播放

    首先在官网下载live555:http://www.live555.com/mediaServer/#downloading当然是现在windows的版本了!!上官网下载FFmpeg:http://f ...

  3. Python+Selenium中级篇之8-Python自定义封装一个简单的Log类《转载》

    Python+Selenium中级篇之8-Python自定义封装一个简单的Log类: https://blog.csdn.net/u011541946/article/details/70198676

  4. 三十六、SAP的调试模式

    一.在执行界面,输入/h, 左下角会提示调试模式被激活 二.点击运行,就会跳出调试界面 三.调试界面用法

  5. 168-PHP 输出系统当前时间

    <body style="font-family:'华文彩云'; color:#0000CC; font-size:20px"> 系统的当前时间是: <?php ...

  6. sql server C#操作。原文在收藏页面

    C#操作SQL Server数据库   1.概述 2.连接字符串的写法 3.SqlConnection对象 4.SqlCommand对象 5.SqlDataReader对象 6.DataSet对象 7 ...

  7. cf 1241 D. Sequence Sorting(思维)

    题意: 一个序列有n个数,有一种操作,你可以选一个数x,使这个序列中等于x的数都移到序列头或尾. 问最少几次操作后,可以使这个序列非降序. 思路: (以下说bi移动到哪里,其实就是指a1……an中等于 ...

  8. 常见的http错误

    错误类型: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 2xx (成功) 表示成功处理了请求的状态代码. 3xx (重定向) 表示要完成请求,需要进一步操作. 通常,这些状态 ...

  9. HDU 5464:Clarke and problem

    Clarke and problem  Accepts: 130  Submissions: 781  Time Limit: 2000/1000 MS (Java/Others)  Memory L ...

  10. POJ 1284:Primitive Roots 求原根的数量

    Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3381   Accepted: 1980 D ...