Split file by data group

Hi all,

I'm having a little trouble solving a file split I need to get done.

I have the following data:

1. Light
1A. Light Soft
texture: it's soft
color: the color value is that of something light
vital statistics: srm: 23 og: 1.035 sp: 1.065
comment: this is nice if you like light colored soft things

1B. Medium
texture: it's soft-ish
color: the color is similar to light soft but because of the difference in texture it appears slightly darker to the naked eye
vital statistics: srm: 30 og: 1.020 sp: 1.070
comment: this is nice if you like light colored soft-ish things

2. German Stlye
2A. Blue Jeans
texture: jeany
color: blue stoopid
vital statistics: srm: 22 og: 1.045 sp: 1.211
comment: german blue jeans are really different that other blue jeans.

3. Last Example Category
3A. This is stoopid
texture: huh?
color: umm... white and black?
vital statustics: srm: 11 og: 1.222 sp: 1.222
comment: ugg

Desired Output

Light.dat

category|style|texture|color|srm|og|sp|comment
Light|Light Soft|it's soft|the color value is that of something light|23|1.035|1.065|this is nice if you like light colored soft things
Light|Medium|it's soft-ishthe color is similar to light soft but because of the difference in texture it appears slightly darker to the naked eye|30|1.020|1.070|this is nice if you like light colored soft-ish things

German Style.dat

category|style|texture|color|srm|og|sp|comment
German Style|Blue Jeans|jeany|blue stoopid|22|1.045|1.211|german blue jeans are really different that other blue jeans.

Last Example Category.dat

category|style|texture|color|srm|og|sp|comment
Last Example Category|This is stoopid|huh?|umm... white and black?|11|1.222|1.222|ugg

I realize that this is kind of a tall order and I really appreciate any help you can offer, maybe it's just because it's late at night, but I've just got nothing on this one.

I'd prefer a script in bash or awk.

THANKS!

Not finished, but this maybe give you some helps.

$ sed 's/^[0-9][A-Z]\. \|texture: \|^color: \|^vital statistics: srm: \| og: \| sp: \|^comment: /|/g' urfile
1. Light
|Light Soft
|it's soft
|the color value is that of something light
|23|1.035|1.065
|this is nice if you like light colored soft things

|Medium
|it's soft-ish
|the color is similar to light soft but because of the difference in texture it appears slightly darker to the naked eye
|30|1.020|1.070
|this is nice if you like light colored soft-ish things

2. German Stlye
|Blue Jeans
|jeany
|blue stoopid
|22|1.045|1.211
|german blue jeans are really different that other blue jeans.

3. Last Example Category
|This is stoopid
|huh?
|umm... white and black?
|11|1.222|1.222
|ugg

OP, base on your data sample and required output:

# cat awk.script
BEGIN{
        x="|"
        y=".dat"
        z="category|style|texture|color|srm|og|sp|comment"
     }
END{print r > (n y)}
        int($1)"."==$1{
                        if(r){
                                print r > (n y)
                                r=""
                             }
                        sub($1FS,"")
                        n=$0
                        }
        $1 ~ /[A-Z]\./{
                        sub($1FS,"")
                        r  = r ? r ORS n x $0: z ORS n x $0
                        }
        /vital/{
                        gsub(/[a-z]| /,"")
                        gsub("::","")
                        gsub(":","|")
                        r = r x $0
                }
        /^[a-z]/{
                        r = r x substr($0,(match($0,":")+2))
                }
# awk -f awk.script sample_file
# cat Light.dat
category|style|texture|color|srm|og|sp|comment
Light|Light Soft|it's soft|the color value is that of something light|23|1.035|1.065|this is nice if you like light colored soft things
Light|Medium|it's soft-ish|the color is similar to light soft but because of the difference in texture it appears slightly darker to the naked eye|30|1.020|1.070|this is nice if you like light colored soft-ish things
# cat German\ Stlye.dat
category|style|texture|color|srm|og|sp|comment
German Stlye|Blue Jeans|jeany|blue stoopid|22|1.045|1.211|german blue jeans are really different that other blue jeans.
# cat Last\ Example\ Category.dat
category|style|texture|color|srm|og|sp|comment
Last Example Category|This is stoopid|huh?|umm... white and black?|11|1.222|1.222|ugg

That was too much to fit in one line :rolleyes:

PS. Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.

Definitely, thank you very much for your help with this, much appreciated!

Thanks!

I always like to answer with oneliner's but for this problem the onliner became too long for my screen :rolleyes: and I take the advantage to add the most wanted whitespace :wink:

Can you confirm please that is working as expected on real data file not just on sample data :wink:

PS. Thank you both for credits and appreciation :wink:

I will be able to this evening, I will have to make a few modifications to the script and won't have access to my servers till later today.

Pfeww, that was fun :). Not as nice as a single script, but I liked trying another approach.

sed -r     '/vital/{s/\w+ \w+://;s/(\w+: \w+)/\n\1/g};' infile                  |
awk -F': ' 'function prl() { if(s!=""){print s>f".dat"}; sub(/[^ ]* /,"")       }
            BEGIN          { h="category|style|texture|color|srm|og|sp|comment" }
            /^[0-9]+\./    { prl(); f=$1; print h>f".dat"; s=""                 }
            /^[0-9]+[A-Z]/ { prl(); s=f"|"$1                                    }
            /:/            { s=s"|"$2                                           }
            END            { prl()                                              }'

-or-

sed        '/vital/{s/\w\+ \w\+://;s/\(\w\+: \w\+\)/\n\1/g};' infile            |

if your sed does not support -r

---------- Post updated at 23:21 ---------- Previous update was at 22:34 ----------

They will ask me where I got all those bits and who my accomplice is, you know :smiley:

They only have to read the forums to see how rubbish my sed is... they won't suspect a thing :slight_smile:

Okay, finally got back to finishing this off, I hacked it up pretty ugly but it works as intended so here it goes...

Example Input:

$ cat ./scripts/tests/beers.dat
1. LIGHT LAGER
1A. Lite American Lager
Aroma: Little to no malt aroma, although it can be grainy, sweet or corn-like if present.  Hop aroma may range from none to a light, spicy or floral hop presence.  Low levels of yeast character (green apples, DMS, or fruitiness) are optional but acceptable.  No diacetyl.
Appearance: Very pale straw to pale yellow color.  White, frothy head seldom persists.  Very clear.
Flavor: Crisp and dry flavor with some low levels of grainy or corn-like sweetness.  Hop flavor ranges from none to low levels.  Hop bitterness at low level.  Balance may vary from slightly malty to slightly bitter, but is relatively close to even.  High levels of carbonation may provide a slight acidity or dry "sting."  No diacetyl.  No fruitiness.
Mouthfeel: Very light body from use of a high percentage of adjuncts such as rice or corn.  Very highly carbonated with slight carbonic bite on the tongue.  May seem watery.
Overall Impression: Very refreshing and thirst quenching.
Comments: A lower gravity and lower calorie beer than standard international lagers.  Strong flavors are a fault. Designed to appeal to the broadest range of the general public as possible.
Ingredients: Two- or six-row barley with high percentage (up to 40%) of rice or corn as adjuncts.
Vital Statistics:    OG:    1.028 - 1.040    IBUs:    8 - 12    FG:    0.998 - 1.008    SRM:    2 - 3    ABV:    2.8 - 4.2%
Commercial Examples: Bitburger Light, Sam Adams Light, Heineken Premium Light, Miller Lite, Bud Light, Coors Light, Baltika #1 Light, Old Milwaukee Light, Amstel Light

1B. Standard American Lager
Aroma: Little to no malt aroma, although it can be grainy, sweet or corn-like if present.  Hop aroma may range from none to a light, spicy or floral hop presence.  Low levels of yeast character (green apples, DMS, or fruitiness) are optional but acceptable.  No diacetyl.
Appearance: Very pale straw to medium yellow color.  White, frothy head seldom persists.  Very clear.
Flavor: Crisp and dry flavor with some low levels of grainy or corn-like sweetness.  Hop flavor ranges from none to low levels.  Hop bitterness at low to medium-low level.  Balance may vary from slightly malty to slightly bitter, but is relatively close to even.  High levels of carbonation may provide a slight acidity or dry "sting."  No diacetyl.  No fruitiness.
Mouthfeel: Light body from use of a high percentage of adjuncts such as rice or corn.  Very highly carbonated with slight carbonic bite on the tongue.
Overall Impression: Very refreshing and thirst quenching.  
Comments: Strong flavors are a fault.  An international style including the standard mass-market lager from most countries.
Ingredients: Two- or six-row barley with high percentage (up to 40%) of rice or corn as adjuncts.
Vital Statistics:    OG:    1.040 - 1.050    IBUs:    8 - 15    FG:    1.004 - 1.010    SRM:    2 - 4    ABV:    4.2 - 5.3%
Commercial Examples: Pabst Blue Ribbon, Miller High Life, Budweiser, Baltika #3 Classic, Kirin Lager, Grain Belt Premium Lager, Molson Golden, Labatt Blue, Coors Original, Foster's Lager

14. INDIA PALE ALE (IPA)
14A. English IPA
Aroma: A moderate to moderately high hop aroma of floral, earthy or fruity nature is typical, although the intensity of hop character is usually lower than American versions.  A slightly grassy dry-hop aroma is acceptable, but not required.  A moderate caramel-like or toasty malt presence is common.  Low to moderate fruitiness, either from esters or hops, can be present.  Some versions may have a sulfury note, although this character is not mandatory.
Appearance: Color ranges from golden amber to light copper, but most are pale to medium amber with an orange-ish tint.  Should be clear, although unfiltered dry-hopped versions may be a bit hazy.  Good head stand with off-white color should persist.
Flavor: Hop flavor is medium to high, with a moderate to assertive hop bitterness.  The hop flavor should be similar to the aroma (floral, earthy, fruity, and/or slightly grassy).  Malt flavor should be medium-low to medium-high, but should be noticeable, pleasant, and support the hop aspect.  The malt should show an English character and be somewhat bready, biscuit-like, toasty, toffee-like and/or caramelly.  Despite the substantial hop character typical of these beers, sufficient malt flavor, body and complexity to support the hops will provide the best balance. Very low levels of diacetyl are acceptable, and fruitiness from the fermentation or hops adds to the overall complexity.  Finish is medium to dry, and bitterness may linger into the aftertaste but should not be harsh.  If high sulfate water is used, a distinctively minerally, dry finish, some sulfur flavor, and a lingering bitterness are usually present.  Some clean alcohol flavor can be noted in stronger versions.  Oak is inappropriate in this style.
Mouthfeel: Smooth, medium-light to medium-bodied mouthfeel without hop-derived astringency, although moderate to medium-high carbonation can combine to render an overall dry sensation in the presence of malt sweetness.  Some smooth alcohol warming can and should be sensed in stronger (but not all) versions.  
Overall Impression: A hoppy, moderately strong pale ale that features characteristics consistent with the use of English malt, hops and yeast.  Has less hop character and a more pronounced malt flavor than American versions.
History: Brewed to survive the voyage from England to India.  The temperature extremes and rolling of the seas resulted in a highly attenuated beer upon arrival.  English pale ales were derived from India Pale Ales.
Comments: A pale ale brewed to an increased gravity and hop rate.  Modern versions of English IPAs generally pale in comparison (pun intended) to their ancestors.  The term "IPA" is loosely applied in commercial English beers today, and has been (incorrectly) used in beers below 4% ABV.  Generally will have more finish hops and less fruitiness and/or caramel than English pale ales and bitters.  Fresher versions will obviously have a more significant finishing hop character.
Ingredients: Pale ale malt (well-modified and suitable for single-temperature infusion mashing); English hops; English yeast that can give a fruity or sulfury/minerally profile. Refined sugar may be used in some versions.  High sulfate and low carbonate water is essential to achieving a pleasant hop bitterness in authentic Burton versions, although not all examples will exhibit the strong sulfate character.
Vital Statistics:    OG:    1.050 - 1.075    IBUs:    40 - 60    FG:    1.010 - 1.018    SRM:    8 - 14    ABV:    5 - 7.5%
Commercial Examples: Meantime India Pale Ale, Freeminer Trafalgar IPA, Fuller's IPA, Ridgeway Bad Elf, Summit India Pale Ale, Samuel Smith's India Ale, Hampshire Pride of Romsey IPA, Burton Bridge Empire IPA,Middle Ages ImPailed Ale, Goose Island IPA, Brooklyn East India Pale Ale

14B. American IPA
Aroma: A prominent to intense hop aroma with a citrusy, floral, perfume-like, resinous, piney, and/or fruity character derived from American hops.  Many versions are dry hopped and can have an additional grassy aroma, although this is not required.  Some clean malty sweetness may be found in the background, but should be at a lower level than in English examples.  Fruitiness, either from esters or hops, may also be detected in some versions, although a neutral fermentation character is also acceptable.  Some alcohol may be noted.
Appearance: Color ranges from medium gold to medium reddish copper; some versions can have an orange-ish tint.  Should be clear, although unfiltered dry-hopped versions may be a bit hazy.  Good head stand with white to off-white color should persist.
Flavor: Hop flavor is medium to high, and should reflect an American hop character with citrusy, floral, resinous, piney or fruity aspects.  Medium-high to very high hop bitterness, although the malt backbone will support the strong hop character and provide the best balance.  Malt flavor should be low to medium, and is generally clean and malty sweet although some caramel or toasty flavors are acceptable at low levels. No diacetyl.  Low fruitiness is acceptable but not required.  The bitterness may linger into the aftertaste but should not be harsh.  Medium-dry to dry finish.  Some clean alcohol flavor can be noted in stronger versions.  Oak is inappropriate in this style.  May be slightly sulfury, but most examples do not exhibit this character.
Mouthfeel: Smooth, medium-light to medium-bodied mouthfeel without hop-derived astringency, although moderate to medium-high carbonation can combine to render an overall dry sensation in the presence of malt sweetness.  Some smooth alcohol warming can and should be sensed in stronger (but not all) versions.  Body is generally less than in English counterparts.
Overall Impression: A decidedly hoppy and bitter, moderately strong American pale ale.
History: An American version of the historical English style, brewed using American ingredients and attitude.
Ingredients: Pale ale malt (well-modified and suitable for single-temperature infusion mashing); American hops; American yeast that can give a clean or slightly fruity profile. Generally all-malt, but mashed at lower temperatures for high attenuation.  Water character varies from soft to moderately sulfate.  Versions with a noticeable Rye character ("RyePA") should be entered in the Specialty category.
Vital Statistics:    OG:    1.056 - 1.075    IBUs:    40 - 70    FG:    1.010 - 1.018    SRM:    6 - 15    ABV:    5.5 - 7.5%
Commercial Examples: Bell's Two-Hearted Ale, AleSmith IPA, Russian River Blind Pig IPA, Stone IPA, Three Floyds Alpha King, Great Divide Titan IPA, Bear Republic Racer 5 IPA, Victory Hop Devil, Sierra Nevada Celebration Ale, Anderson Valley Hop Ottin',  Dogfish Head 60 Minute IPA, Founder's Centennial IPA, Anchor Liberty Ale, Harpoon IPA, Avery IPA

Example Output:

$ ls ./scripts/tests/beers
INDIA PALE ALE (IPA).dat  
LIGHT LAGER.dat  

$ cat ./scripts/tests/beers/INDIA\ PALE\ ALE\ \(IPA\).dat
Category|Style|Aroma|Appearance|Flavor|Mouthfeel|Overall Impression|Comments|Ingredients|OG|IBUs|FG|SRM|ABV|Commercial Examples
INDIA PALE ALE (IPA)|English IPA|A moderate to moderately high hop aroma of floral, earthy or fruity nature is typical, although the intensity of hop character is usually lower than American versions.  A slightly grassy dry-hop aroma is acceptable, but not required.  A moderate caramel-like or toasty malt presence is common.  Low to moderate fruitiness, either from esters or hops, can be present.  Some versions may have a sulfury note, although this character is not mandatory.|Color ranges from golden amber to light copper, but most are pale to medium amber with an orange-ish tint.  Should be clear, although unfiltered dry-hopped versions may be a bit hazy.  Good head stand with off-white color should persist.|Hop flavor is medium to high, with a moderate to assertive hop bitterness.  The hop flavor should be similar to the aroma (floral, earthy, fruity, and/or slightly grassy).  Malt flavor should be medium-low to medium-high, but should be noticeable, pleasant, and support the hop aspect.  The malt should show an English character and be somewhat bready, biscuit-like, toasty, toffee-like and/or caramelly.  Despite the substantial hop character typical of these beers, sufficient malt flavor, body and complexity to support the hops will provide the best balance. Very low levels of diacetyl are acceptable, and fruitiness from the fermentation or hops adds to the overall complexity.  Finish is medium to dry, and bitterness may linger into the aftertaste but should not be harsh.  If high sulfate water is used, a distinctively minerally, dry finish, some sulfur flavor, and a lingering bitterness are usually present.  Some clean alcohol flavor can be noted in stronger versions.  Oak is inappropriate in this style.|Smooth, medium-light to medium-bodied mouthfeel without hop-derived astringency, although moderate to medium-high carbonation can combine to render an overall dry sensation in the presence of malt sweetness.  Some smooth alcohol warming can and should be sensed in stronger (but not all) versions.  |A hoppy, moderately strong pale ale that features characteristics consistent with the use of English malt, hops and yeast.  Has less hop character and a more pronounced malt flavor than American versions.|Brewed to survive the voyage from England to India.  The temperature extremes and rolling of the seas resulted in a highly attenuated beer upon arrival.  English pale ales were derived from India Pale Ales.|A pale ale brewed to an increased gravity and hop rate.  Modern versions of English IPAs generally pale in comparison (pun intended) to their ancestors.  The term "IPA" is loosely applied in commercial English beers today, and has been (incorrectly) used in beers below 4% ABV.  Generally will have more finish hops and less fruitiness and/or caramel than English pale ales and bitters.  Fresher versions will obviously have a more significant finishing hop character.|Pale ale malt (well-modified and suitable for single-temperature infusion mashing); English hops; English yeast that can give a fruity or sulfury/minerally profile. Refined sugar may be used in some versions.  High sulfate and low carbonate water is essential to achieving a pleasant hop bitterness in authentic Burton versions, although not all examples will exhibit the strong sulfate character.| 1.050 - 1.075|40 - 60|1.010 - 1.018|8 - 14|5 - 7.5%|Meantime India Pale Ale, Freeminer Trafalgar IPA, Fuller's IPA, Ridgeway Bad Elf, Summit India Pale Ale, Samuel Smith's India Ale, Hampshire Pride of Romsey IPA, Burton Bridge Empire IPA,Middle Ages ImPailed Ale, Goose Island IPA, Brooklyn East India Pale Ale
INDIA PALE ALE (IPA)|American IPA|A prominent to intense hop aroma with a citrusy, floral, perfume-like, resinous, piney, and/or fruity character derived from American hops.  Many versions are dry hopped and can have an additional grassy aroma, although this is not required.  Some clean malty sweetness may be found in the background, but should be at a lower level than in English examples.  Fruitiness, either from esters or hops, may also be detected in some versions, although a neutral fermentation character is also acceptable.  Some alcohol may be noted.|Color ranges from medium gold to medium reddish copper; some versions can have an orange-ish tint.  Should be clear, although unfiltered dry-hopped versions may be a bit hazy.  Good head stand with white to off-white color should persist.|Hop flavor is medium to high, and should reflect an American hop character with citrusy, floral, resinous, piney or fruity aspects.  Medium-high to very high hop bitterness, although the malt backbone will support the strong hop character and provide the best balance.  Malt flavor should be low to medium, and is generally clean and malty sweet although some caramel or toasty flavors are acceptable at low levels. No diacetyl.  Low fruitiness is acceptable but not required.  The bitterness may linger into the aftertaste but should not be harsh.  Medium-dry to dry finish.  Some clean alcohol flavor can be noted in stronger versions.  Oak is inappropriate in this style.  May be slightly sulfury, but most examples do not exhibit this character.|Smooth, medium-light to medium-bodied mouthfeel without hop-derived astringency, although moderate to medium-high carbonation can combine to render an overall dry sensation in the presence of malt sweetness.  Some smooth alcohol warming can and should be sensed in stronger (but not all) versions.  Body is generally less than in English counterparts.|A decidedly hoppy and bitter, moderately strong American pale ale.|An American version of the historical English style, brewed using American ingredients and attitude.|Pale ale malt (well-modified and suitable for single-temperature infusion mashing); American hops; American yeast that can give a clean or slightly fruity profile. Generally all-malt, but mashed at lower temperatures for high attenuation.  Water character varies from soft to moderately sulfate.  Versions with a noticeable Rye character ("RyePA") should be entered in the Specialty category.| 1.056 - 1.075|40 - 70|1.010 - 1.018|6 - 15|5.5 - 7.5%|Bell's Two-Hearted Ale, AleSmith IPA, Russian River Blind Pig IPA, Stone IPA, Three Floyds Alpha King, Great Divide Titan IPA, Bear Republic Racer 5 IPA, Victory Hop Devil, Sierra Nevada Celebration Ale, Anderson Valley Hop Ottin',  Dogfish Head 60 Minute IPA, Founder's Centennial IPA, Anchor Liberty Ale, Harpoon IPA, Avery IPA

$ cat ./scripts/tests/beers/LIGHT\ LAGER.dat
Category|Style|Aroma|Appearance|Flavor|Mouthfeel|Overall Impression|Comments|Ingredients|OG|IBUs|FG|SRM|ABV|Commercial Examples
LIGHT LAGER|Lite American Lager|Little to no malt aroma, although it can be grainy, sweet or corn-like if present.  Hop aroma may range from none to a light, spicy or floral hop presence.  Low levels of yeast character (green apples, DMS, or fruitiness) are optional but acceptable.  No diacetyl.|Very pale straw to pale yellow color.  White, frothy head seldom persists.  Very clear.|Crisp and dry flavor with some low levels of grainy or corn-like sweetness.  Hop flavor ranges from none to low levels.  Hop bitterness at low level.  Balance may vary from slightly malty to slightly bitter, but is relatively close to even.  High levels of carbonation may provide a slight acidity or dry "sting."  No diacetyl.  No fruitiness.|Very light body from use of a high percentage of adjuncts such as rice or corn.  Very highly carbonated with slight carbonic bite on the tongue.  May seem watery.|Very refreshing and thirst quenching.|A lower gravity and lower calorie beer than standard international lagers.  Strong flavors are a fault. Designed to appeal to the broadest range of the general public as possible.|Two- or six-row barley with high percentage (up to 40%) of rice or corn as adjuncts.| 1.028 - 1.040|8 - 12|0.998 - 1.008|2 - 3|2.8 - 4.2%|Bitburger Light, Sam Adams Light, Heineken Premium Light, Miller Lite, Bud Light, Coors Light, Baltika #1 Light, Old Milwaukee Light, Amstel Light
LIGHT LAGER|Standard American Lager|Little to no malt aroma, although it can be grainy, sweet or corn-like if present.  Hop aroma may range from none to a light, spicy or floral hop presence.  Low levels of yeast character (green apples, DMS, or fruitiness) are optional but acceptable.  No diacetyl.|Very pale straw to medium yellow color.  White, frothy head seldom persists.  Very clear.|Crisp and dry flavor with some low levels of grainy or corn-like sweetness.  Hop flavor ranges from none to low levels.  Hop bitterness at low to medium-low level.  Balance may vary from slightly malty to slightly bitter, but is relatively close to even.  High levels of carbonation may provide a slight acidity or dry "sting."  No diacetyl.  No fruitiness.|Light body from use of a high percentage of adjuncts such as rice or corn.  Very highly carbonated with slight carbonic bite on the tongue.|Very refreshing and thirst quenching.  |Strong flavors are a fault.  An international style including the standard mass-market lager from most countries.|Two- or six-row barley with high percentage (up to 40%) of rice or corn as adjuncts.| 1.040 - 1.050|8 - 15|1.004 - 1.010|2 - 4|4.2 - 5.3%|Pabst Blue Ribbon, Miller High Life, Budweiser, Baltika #3 Classic, Kirin Lager, Grain Belt Premium Lager, Molson Golden, Labatt Blue, Coors Original, Foster's Lager

Awk program file:

$ cat ./scripts/split_group2.awk
function f1()                            { if(dat!="") {print dat > ( path cat ext ) } }

BEGIN                                    {
                                           path="/tools/scripts/tests/beers/"
                                           dlm="|"
                                           ext=".dat"
                                           head="Category|Style|Aroma|Appearance|Flavor|Mouthfeel|Overall Impression|Ingredients|OG|IBUs|FG|SRM|ABV|Commercial Examples"
                                         }

/^[0-9]+\./                              {
                                           f1()
                                           cat=substr($0,(match($0," ")+1))
                                           print head > ( path cat ext )
                                           dat = ""
                                         }

/^[0-9]+[A-Z]+\./                        {
                                           f1()
                                           dat = cat dlm substr($0,(match($0," ")+1))
                                         }

/^Vital/                                 {
                                           gsub(/[a-zA-Z]/,"")
                                           gsub("::","")
                                           gsub(":","|")
                                           dat = dat dlm $0
                                         }

/^[A-Z]/ && (!/^History/ || !/^Comments) { dat = dat dlm substr($0,(match($0,":")+2)) }

END                                      { f1() }

The actual line submitted:

$ sed 's/\t//g' ./scripts/tests/beers.dat | awk -f ./scripts/split_group2.awk

I am using sed to cleanup the tabs from the Vital Statistics: lines of the input file, I suppose I could've just done so in awk, but, whatever...