Processing curl output in perl Processing curl output in perl curl curl

Processing curl output in perl


There is no need to split on <li> elements or use a parser (you don't care about the structure of the document), so you can just search for the regsvr32.exe string up to the next < character.

curl $msft_url | perl -lane 'print for ( m|regsvr32.exe (.+?.dll)<|g );'

To handle more than one capture, you will need an extra while loop to iterate over the pairs of matches. The shift command pulls the first element off of an array, the reverse command reverses an array. This captures 2 strings and prints them in reverse order:

curl $msft_url | perl -lane '@m = m|(regsvr32).exe (.+?.dll)<|g; while (@m) { print join " ", reverse(shift @m, shift @m) };'


I've discovered how to do the other method I was trying (sort of), which was to have perl do the splitting. The key is that the -a and -F do not determine record-splitting behavior. Only -0 does.

-a splits each record (internally) into the @F array, which the documentation now seems completely clear on. The @F array is mostly intended to be used awk style so that one can very easily say "print the 2nd column" ($F[1]). So I could rephrase as "-0 is generally how you get rows and -a is generally how you get columns, roughly speaking."

However, it can be made to serve the purpose:

curl -vs \https://support.microsoft.com/en-us/help/971058/how-do-i-reset-windows-update-components 2>&1 \| perl -F'<\/li>' -lane 'foreach my $match (map { /regsvr32.exe (.+?.dll)/ } @F) {print"$match"}

I, for obvious reasons, prefer the accepted solution for this problem, but I could see this approach being handy elsewhere.PS--A -0 solution (using records split on >) is:

| perl -0x3c -ne 'print "$1\n" if /regsvr32.exe (.+?\.dll)/'