home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!psgrain!m2xenix!mtek!bud
- From: bud@mtek.com (Bud Hovell)
- Subject: sed how to
- Reply-To: bud@mtek.com
- Organization: MTEK International, Inc.
- Distribution: usa
- Date: Thu, 7 Jan 93 23:46:38 GMT
- Message-ID: <1993Jan7.234638.6106@mtek.com>
- Keywords: help!
- Lines: 47
-
-
- Sorry, but it appears my recently-acquired Nutshell Book on Sed &
- Awk has taken legs (dammit, dammit, dammit!!!), so I need help
- from some kind soul who is more sed-literate than I currently am.
-
- Given rows of pipe-delimited ascii database records of this form:
-
- 0113|Hog Farms|0213|Hogs|
- 0114|Poultry & Egg Farms|0251|Broiler, Fryer, and Roaster Chickens|
- ||0252|Chicken Eggs|
- ||0253|Turkeys and Turkey Eggs|
- ||0259|Poultry and Eggs NEC|
- 0119|Livestock Comb'n Farms|0219|General Livestock NEC|
- ||027|Animal Specialties|
- 0121|Honey & Other Apiary Prod. Farms|0279|Animal Specialties NEC|
- 0122|Horse & Other Equine Farms|0272|Horses and Other Equines|
-
- ....what sed construct will give me output in this form:
-
- 0113|Hog Farms|0213|Hogs|
- 0114|Poultry & Egg Farms|0251|Broiler, Fryer, and Roaster Chickens|
- 0114|Poultry & Egg Farms|0252|Chicken Eggs|
- 0114|Poultry & Egg Farms|0253|Turkeys and Turkey Eggs|
- 0114|Poultry & Egg Farms|0259|Poultry and Eggs NEC|
- 0119|Livestock Comb'n Farms|0219|General Livestock NEC|
- 0119|Livestock Comb'n Farms|027|Animal Specialties|
- 0121|Honey & Other Apiary Prod. Farms|0279|Animal Specialties NEC|
- 0122|Horse & Other Equine Farms|0272|Horses and Other Equines|
-
- That is.....
-
- When a line is evaluated to have values in the first pipe-delimited
- field, save the values of the first two fields and print out the line.
-
- Then, on each subsequent line evaluated, if the first field is empty,
- substitute into the first two fields the values previously saved and
- print out the line.
-
- Else print out the line and save its values (as above) for possible
- substitution on subsequent line(s), etc.
-
- Any help would be very greatly appreciated.
- --
- ________________________________________________________________
- bud@mtek.com ... uunet!m2xenix!mtek!bud ... bud@rigel.cs.pdx.edu
- MTEK International, Inc. Throughput Technology Corp.
- Throughput!
-