OT: scripting help - can you check a string for starts with?

John Summerfield debian at herakles.homelinux.org
Wed Dec 19 06:58:59 UTC 2007


Tony Nelson wrote:
> At 8:48 PM -0500 12/18/07, James Pifer wrote:
>> Need a bit of scripting help. I have a very small script with a case
>> statement. The object of the case statement is derived from the
>> dmidecode command to determine the type of machine it is, if possible.
>> It works fine, but we're finding that a lot of the HP type machines
>> respond with a model number plus other information. For example, we
>> might get these two:
>>
>> HP Compaq dc7700 30GB6000
>> HP Compaq dc7700 60GB6000
Here's a real one.
Product Name: HP Compaq dc7700 Small Form Factor

>>
>> Those are completely made up, the point being that we want to match on
>> just "HP Compaq dc7700" and forget the rest.
>  ...
> 
> case $printername in
>     "HP Compaq dc7700"*) echo "found $printername" ;;
> esac

<chortle>

the example's fine, but read again what he's looking at:-)


I have a bash book from Oreilly, it's good. Jacques has a newer edition 
than mine.

I do lots of data extraction using grep, sed and awk. Can do almost 
anything with those.

This illustrats a few key points of awk without being overly complicated 
(or complete)


[root at potoroo ~]# dmidecode  \
   | awk -F : '/Product Name:/ {print $2}; /Manufacturer:/ {print $2}'
  Hewlett-Packard
  HP Compaq dc7700 Small Form Factor
  Hewlett-Packard
  0A54h
  Hewlett-Packard
  Intel
  Intel
  JEDEC ID
  JEDEC ID
  JEDEC ID
  JEDEC ID
  Not Specified
[root at potoroo ~]#



-- 

Cheers
John

-- spambait
1aaaaaaa at coco.merseine.nu  Z1aaaaaaa at coco.merseine.nu
-- Advice
http://webfoot.com/advice/email.top.php
http://www.catb.org/~esr/faqs/smart-questions.html
http://support.microsoft.com/kb/555375

You cannot reply off-list:-)




More information about the fedora-list mailing list