help pulling ${VARS} out of a web page user curl

Here is the code I have so far

#!/bin/bash

INFOF="/tmp/mac.info"

curl --silent http://www.everymac.com/systems/apple/macbook_pro/specs/macbook-pro-core-2-duo-2.8-aluminum-17-mid-2009-unibody-specs.html "$INFOF"

I want help putting these specs into a vars
Standard Ram: value into $VAR1
Maximum Ram: value into $VAR2
Apple Model No: value into $VAR3
Model ID: into $VAR4

I was thinking

cat | awk

would do the trick but I am lost in getting these to work correctly.

Thanks in advance.

I assume you wanted the value into shell variables, not awk variables since you used a dollar sign prefix in your example.

First example works only in Kshell (cleaner if you're willing to use kshell). Second example, with a hack needed to get the variables will work in bash. I don't regularly use bash, so maybe there is a better/easier way, but I'm not finding it in my brain tonight.

#!/usr/bin/env ksh

url="http://www.everymac.com/systems/apple/macbook_pro/specs/macbook-pro-core-2-duo-2.8-aluminum-17-mid-2009-unibody-specs.html"

curl --silent "$url" | awk  '{gsub( "<[^>]*>", "\n" ); gsub( "\r", "" );  print;}'   |awk '
    /Standard RAM/      {snarf = 1; what = "sram"; next; }
    /Maximum RAM:/      {snarf = 1; what = "mram"; next; }
    /Apple Model No:/   {snarf = 1; what = "modeln"; next; }
    /Model ID:/         {snarf = 1; what = "modeli"; next; }

    NF > 0 && snarf { v[what] = $0; snarf = 0; next; }

    END { printf( "%s,%s,%s,%s\n", v["sram"], v["mram"], v["modeln"], v["modeli"] ); } ' | IFS=, read var1 var2 var3 var4

echo "v1=$var1  v2=$var2  v3=$var3  v4=$var4"
#!/usr/bin/env bash
url="http://www.everymac.com/systems/apple/macbook_pro/specs/macbook-pro-core-2-duo-2.8-aluminum-17-mid-2009-unibody-specs.html"

# not as clean, but works...
curl --silent "$url" | awk  '{gsub( "<[^>]*>", "\n" ); gsub( "\r", "" );  print;}'  | awk '
    /Standard RAM/      {snarf = 1; what = "sram"; next; }
    /Maximum RAM:/      {snarf = 1; what = "mram"; next; }
    /Apple Model No:/   {snarf = 1; what = "modeln"; next; }
    /Model ID:/         {snarf = 1; what = "modeli"; next; }

    NF > 0 && snarf {  v[what] = $0;  snarf = 0; next; }
   
 END {  printf( "var1=\"%s\"\nvar2=\"%s\"\nvar3=\"%s\"\nvar4=\"%s\"\n", v["sram"], v["mram"], v["modeln"], v["modeli"] ); } ' >/tmp/hack.$$

. /tmp/hack.$$
rm /tmp/hack.$$

echo "v1=$var1  v2=$var2  v3=$var3  v4=$var4"

Hope one of these helps.