Find the answer to your Linux question:
Results 1 to 4 of 4
I am needing to extract unknown text out of a string and set it as a variable. Here is the pattern I am dealing with: Code: Category:</span> Soups and Chowders</p> ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Posts
    41

    Extracting unknown text to create variable


    I am needing to extract unknown text out of a string and set it as a variable. Here is the pattern I am dealing with:

    Code:
    Category:</span> Soups and Chowders</p>
    I need to set whatever the category is as a variable. In this case it would be:

    myCategory="Soups and Chowders"

    but it could be Cookies or Main Dishes, etc.

    In any case, there's always one whitespace after Category:</span> and never a whitespace between the actual recipe category and </p>

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    Hmm, this sounds somewhat like a homework question, which is not allowed by forum rules.
    But in dubio pro reo
    Code:
    myCategory=$(echo "Category:</span> Soups and Chowders</p>" | sed 's/^Category:<\/span> \(.*\)<\/p>$/\1/')
    echo ${myCategory}
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Apr 2005
    Posts
    41
    Quote Originally Posted by Irithori View Post
    Hmm, this sounds somewhat like a homework question, which is not allowed by forum rules.
    But in dubio pro reo
    Code:
    myCategory=$(echo "Category:</span> Soups and Chowders</p>" | sed 's/^Category:<\/span> \(.*\)<\/p>$/\1/')
    echo ${myCategory}
    Trust me. I'm 67, am not a student and this surely is not homework. At the moment I am running out of time. My lady has hundreds of recipe files and has always wanted to make them available to family and friends. They only export from her recipe program as individual html pages which have no bells, whistles, navigation buttons and so on. As a Christmas gift I obtained a domain for her and have placed her entire archive on it. I'm just needing to set up some navigation links, spruce up 800+ html pages, etc. It's all done except one link button on each page that's dependent upon what category the current html page is. I will be able to accomplish that in seconds with the category of each page known.

    Whatever, I will try to adapt your routine to my needs. I appreciate your help very much. Thank you and have a good Christmas, if you celebrate.

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,356
    Good luck.
    And Merry Christmas
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •