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. HYSBZ - 1588 营业额统计 (伸展树)

    题意:营业额统计 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额.分析营 ...

  2. 103-PHP定义一个类

    <?php class ren{ //定义人类 } class mao{ //定义猫类 } new ren(); //实例化人类 new mao(); //实例化猫类 new mao(); // ...

  3. gem5-gpu全系统模式

    # 注意:安装好gem5-gpu后再配置全系统环境 # 下载全系统模拟需要的工具,详见http://gem5.org/Running_gem5#Full_System_.28FS.29_Mode,将L ...

  4. javaweb 最简单的分页技术

    原文来自于https://www.cnblogs.com/xwlych/p/6017833.html 个人由加了一点注释,他的代码我运行不起来,弄了好一会 bean包  User.java packa ...

  5. 微软于 snapcraft 上发布 Visual Studio Code 的 Snap 打包版本

    微软在 snapcraft 上发布了 Visual Studio Code 的 Snap 打包版本 .Snap 是 Canonical 主导开发的应用打包格式,与 Flatpak 和 AppImage ...

  6. windows LARGE_INTEGER 错误码输出格式

    如果是负数,I32X 版权声明:本文为博主原创文章,未经博主允许不得转载.

  7. 20 - CommonJS - 规范的具体内容

  8. s5pc100开发板uboot移植

    相关软件下载地址:http://pan.baidu.com/s/16yo8Y 适用于fsc100开发板 交叉编译器arm-cortex_a8-linux-gnueabi-gcc u-boot-2010 ...

  9. 数据库连接池C3P0的使用

    一.直接使用代码链接(一般企业开发不会用到.大多数用方法二) 1.导入jar 2.新建JDBCUtil import java.io.FileInputStream; import java.io.I ...

  10. 文献阅读 - MonoLoco与关于Camera Matrix的笔记

    目录 概览 HighLights Camera Intrinsic Matrix 笔记 Intrinsic Matrix Task-Error - 不确定性任务下确界的计算 输出假设的Laplace分 ...