Unix 从url读取参数

Unix 从url读取参数,unix,awk,Unix,Awk,我正在尝试从URL读取一个参数,我可以读取单行,但我不知道如何在awk中循环,有人能帮忙吗 我有1000多个条目的文件,比如 http://projectreporter.nih.gov/project_info_details.cfm?aid=7714687&icde=0 http://projectreporter.nih.gov/project_info_description.cfm?aid=7896503&icde=0 http://projectreporter.ni

我正在尝试从URL读取一个参数,我可以读取单行,但我不知道如何在awk中循环,有人能帮忙吗

我有1000多个条目的文件,比如

http://projectreporter.nih.gov/project_info_details.cfm?aid=7714687&icde=0
http://projectreporter.nih.gov/project_info_description.cfm?aid=7896503&icde=0
http://projectreporter.nih.gov/project_info_details.cfm?aid=7895320&icde=0
http://projectreporter.nih.gov/project_info_details.cfm?aid=2675186&icde=9195637
我试图只检索“aid=xxxxxxx”,我使用了下面的命令来执行此操作,并获得最后一行的“aid”

awk '{match($0,"aid=([^ &]+)",a)}END{print a[1]}' file1.txt > outputFile.txt
如何在循环中执行相同的操作,以便获得所有发生的事件?
任何帮助都将不胜感激

这将对您尝试的代码进行一些微调

awk 'match($0,/aid[^&]*/){print substr($0,RSTART,RLENGTH)}' Input_file


如果您的单行可以多次出现
aid
,并且您希望打印所有内容,请尝试以下操作

awk '
{
  while(match($0,/aid[^&]*/)){
    print substr($0,RSTART,RLENGTH)
    $0=substr($0,RSTART+RLENGTH)
  }
}
' Input_file

使用GNU
grep
,您可以使用
grep-oP'aid=\K[^&]+'file1.txt
。或者,使用
sed
sed-n's/*?aid=\([^&]*\)./\1/p'file1.txt
似乎您只需要删除
END
。也就是说,将
print
语句与
match