bash script grep using variable fails to find result that actually does exist

后端 未结 2 1671
谎友^
谎友^ 2021-01-29 05:01

I have a bash script that iterates over a list of links, curl\'s down an html page per link, greps for a particular string format (syntax is: CVE-####-####), removes the surroun

2条回答
  •  误落风尘
    2021-01-29 05:07

    HTML files can contain carriage returns at the ends of lines, you need to filter those out.

    curl -s "$link" | sed -n '/CVE-/s/<[^>]*>//gp' | tr -d '\r' | while read cve; do
    

    Notice that there's no need to use grep, you can use a regular expression filter in the sed command. (You can also use the tr command in sed to remove characters, but doing this for \r is cumbersome, so I piped to tr instead).

提交回复
热议问题