home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / question / 15303 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.2 KB  |  60 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!psgrain!m2xenix!mtek!bud
  3. From: bud@mtek.com (Bud Hovell)
  4. Subject: sed how to
  5. Reply-To: bud@mtek.com
  6. Organization: MTEK International, Inc.
  7. Distribution: usa
  8. Date: Thu, 7 Jan 93 23:46:38 GMT
  9. Message-ID: <1993Jan7.234638.6106@mtek.com>
  10. Keywords: help!
  11. Lines: 47
  12.  
  13.  
  14. Sorry, but it appears my recently-acquired Nutshell Book on Sed &
  15. Awk has taken legs (dammit, dammit, dammit!!!), so I need help
  16. from some kind soul who is more sed-literate than I currently am.
  17.  
  18. Given rows of pipe-delimited ascii database records of this form:
  19.  
  20.   0113|Hog Farms|0213|Hogs|
  21.   0114|Poultry & Egg Farms|0251|Broiler, Fryer, and Roaster Chickens|
  22.   ||0252|Chicken Eggs|
  23.   ||0253|Turkeys and Turkey Eggs|
  24.   ||0259|Poultry and Eggs NEC|
  25.   0119|Livestock Comb'n Farms|0219|General Livestock NEC|
  26.   ||027|Animal Specialties|
  27.   0121|Honey & Other Apiary Prod. Farms|0279|Animal Specialties NEC|
  28.   0122|Horse & Other Equine Farms|0272|Horses and Other Equines|
  29.  
  30. ....what sed construct will give me output in this form:
  31.  
  32.   0113|Hog Farms|0213|Hogs|
  33.   0114|Poultry & Egg Farms|0251|Broiler, Fryer, and Roaster Chickens|
  34.   0114|Poultry & Egg Farms|0252|Chicken Eggs|
  35.   0114|Poultry & Egg Farms|0253|Turkeys and Turkey Eggs|
  36.   0114|Poultry & Egg Farms|0259|Poultry and Eggs NEC|
  37.   0119|Livestock Comb'n Farms|0219|General Livestock NEC|
  38.   0119|Livestock Comb'n Farms|027|Animal Specialties|
  39.   0121|Honey & Other Apiary Prod. Farms|0279|Animal Specialties NEC|
  40.   0122|Horse & Other Equine Farms|0272|Horses and Other Equines|
  41.  
  42. That is.....
  43.  
  44. When a line is evaluated to have values in the first pipe-delimited
  45. field, save the values of the first two fields and print out the line.
  46.  
  47. Then, on each subsequent line evaluated, if the first field is empty,
  48. substitute into the first two fields the values previously saved and
  49. print out the line.
  50.  
  51. Else print out the line and save its values (as above) for possible
  52. substitution on subsequent line(s), etc.
  53.  
  54. Any help would be very greatly appreciated.
  55. -- 
  56. ________________________________________________________________
  57. bud@mtek.com ... uunet!m2xenix!mtek!bud ... bud@rigel.cs.pdx.edu
  58. MTEK International, Inc.             Throughput Technology Corp.
  59. Throughput!
  60.