usage of sed question for experts

I need a little help with sed. Basically, I need to parse out selections from the output of hddtemp so conky can display some hdd temps for me. I have hddtemp in daemon mode so A simple 'nc localhost 7634' displays the following:

$ nc localhost 7634
|/dev/sg1|ST3640323AS|31|C||/dev/sg2|ST3640323AS|31|C||/dev/sg3|WDC WD1001FALS-00J7B1|36|C||/dev/sg4|WDC WD7501AALS-00J7B0|32|C||/dev/sda|ST3640323AS|31|C||/dev/sdb|ST3640323AS|31|C||/dev/sdc|WDC WD1001FALS-00J7B1|36|C||/dev/sdd|WDC WD7501AALS-00J7B0|32|C|

Just ignore /dev/sdd because it's going away soon. How can I use sed to extract the temps of /dev/sda and /dev/sdb and /dev/sdc so I can insert an appropriate line to my .conkyrc?

I have can do this long hand using the '-cut -cx-y' command:

sda:$color ${execi 300 nc localhost 7634 | cut -c50-51} C

...but I think a series of sed statements would be more power (one to delete everything up to the temp and one to delete everything after the temp) particularlly if the HDD gets swapped out which would change the number of characters in the line.

Thoughts are welcomed and thanks!

Try this to retrieve /dev/sda. It might look a little complicated.

echo $(nc localhost 7634) | sed -n -e "s+.*\(|/dev/sda|[^|]*|[^|]*|[^|]*|\).*+\1+p" 

But I think awk would be a good tool to retrieve the columns you are looking for.

I agree that awk is the tool for this.
It will handle changes in the length of disk names, etc.
better than some other approaches.

Assuming that more than one disk temp is on each input line,
this does something like what you seem to want.
It assumes that the right number of fields will always be provided after the disk name.

devs="/dev/sda /dev/sdb /dev/sdc"

nc localhost 7634  | nawk -F '|' -v devs="$devs"  '
NR ==1 { ndev = split(devs,dev," ") ; if (ndev < 1) exit(1) }

{
        for (i = 1 ; i <= NF; i++) {
                for (d = 1; d <= ndev; d++) {
                        if ($i == dev[d])
                                print dev[d],$(i+2);
                }
        }
}'  -

/dev/sda 31
/dev/sdb 31
/dev/sdc 36

Thanks guys...