Awk Grep文件中以特定模式开头的正则表达式模式

Awk Grep文件中以特定模式开头的正则表达式模式,awk,sed,grep,Awk,Sed,Grep,我正在尝试构建一个shell脚本,它将使用while循环读取一个文件(scope.txt)。作用域文件包含网站域。循环将遍历scope.txt文件,并在另一个名为url.txt的文件中搜索该域。我需要grep模式在url.txt文件和需要的结果一样,在最后提到 作用域文件包含- google.com facebook.com URL文件内容- https://google.com/ukhkj/sdgdsdd/ http://abcs.google.com/sdf/sg/dfg?ijkl=asf

我正在尝试构建一个shell脚本,它将使用while循环读取一个文件(scope.txt)。作用域文件包含网站域。循环将遍历scope.txt文件,并在另一个名为url.txt的文件中搜索该域。我需要grep模式在url.txt文件和需要的结果一样,在最后提到

作用域文件包含-

google.com
facebook.com
URL文件内容-

https://google.com/ukhkj/sdgdsdd/
http://abcs.google.com/sdf/sg/dfg?ijkl=asffdf
https://test.com/sdvs?url=google.com
https://abcd.com/jhhhh/hghv?proxy=https://google.com
https://a.b.c.d.facebook.com/ss/sdfsdf
http://aa.b.c.d.com/dfgdfg/sgfdfg?url=https://google.com

while read -r line; do
cat urls.txt | grep -e "^https\:\/\/$line\|^http\:\/\/$line"
done < scope.txt
我需要的输出-

https://google.com/ukhkj/sdgdsdd/
http://abcs.google.com/sdf/sg/dfg?ijkl=asffdf
https://a.b.c.d.facebook.com/ss/sdfsdf
因为结果输出包含scope.txt文件中提到的特定域的所有域和子域

我试图构建一个shell脚本文件,但没有得到想要的输出 shell脚本的内容-

https://google.com/ukhkj/sdgdsdd/
http://abcs.google.com/sdf/sg/dfg?ijkl=asffdf
https://test.com/sdvs?url=google.com
https://abcd.com/jhhhh/hghv?proxy=https://google.com
https://a.b.c.d.facebook.com/ss/sdfsdf
http://aa.b.c.d.com/dfgdfg/sgfdfg?url=https://google.com

while read -r line; do
cat urls.txt | grep -e "^https\:\/\/$line\|^http\:\/\/$line"
done < scope.txt
读取-r行时
;做
cat url.txt | grep-e“^https\:\/\/$line\ ^http\:\/\/$line”
完成
您可以使用此
grep+sed
解决方案:


grep-Ef对于显示的示例,请尝试以下内容

awk '
FNR==NR{
  arr[$0]
  next
}
{
  for(key in arr){
    if($0~/^https?:\/\// && $0 ~ key"/"){
      print
      next
    }
  }
}
' scope urlfile
说明:添加上述内容的详细说明

awk '                  ##Starting awk program from here.
FNR==NR{               ##Checking condition which will be TRUE when scope file.
  arr[$0]              ##Creating array arr with index of current line.
  next                 ##next will skip all further statements from here.
}
{
  for(key in arr){     ##Traversing through array arr here.
    if($0~/^https?:\/\// && $0 ~ key"/"){  ##Checking if line starts from http/https AND contains key/ here then do following.
      print            ##Printing current line here.
      next             ##next will skip all further statements from here.
    }
  }
}
' scope urlfile        ##Mentioning Input_file names here.