简体   繁体   English

从两个文件bash获取字符串

[英]Get strings from two files bash

I have two files, one with url's other with id's 我有两个文件,一个带有url,另一个带有id

for line in $(cat urls_file); do
for id in $(cat ids_file); do
touch topic_$id
curl $line|grep "data\-topic=">topic_$id
done
done

BUT it does for every $line all the $id 's and i want to do for each line each id. 但是它为每个$ line都执行所有$ id,我想为每个行每个id进行。

BUT it does for every $line all the $id 's and i want to do for each line each id. 但是它为每个$ line都执行所有$ id,我想为每个行每个id进行。

In that case you should use paste to have 2 column data from 2 input files: 在这种情况下,应该使用paste从2个输入文件中获取2列数据:

while read -r line id; do
   curl "$line" | grep 'data-topic=' > "topic_$id"
done < <(paste urls_file ids_file)

There is no need to use touch as curl will create the file anyway. 无需使用touch因为无论如何curl都会创建文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM