The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Enterprise Unix Roundup: The Ghost of Unix Future - Server Watch iBot UNIX and Linux RSS News 0 12-19-2007 08:20 AM
Running UNIX commands remotely in Windows box from Unix box – avoid entering password D.kalpana UNIX for Dummies Questions & Answers 1 04-20-2007 02:24 AM
FTP script for sending a file from one unix directory to another unix server director raja_1234 Shell Programming and Scripting 1 11-30-2006 03:57 AM
Unix Sco Open Server, Windows Computers Problem Access Unix Shared Files Help!!!!! haggo Filesystems, Disks and Memory 2 08-23-2006 08:39 AM
Unix History Question: Why are filenames/dirnames case sentsitive in Unix? deckard UNIX for Dummies Questions & Answers 3 03-26-2005 09:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-27-2007
Registered User
 

Join Date: Sep 2007
Posts: 2
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
UNIX awk help

I am new to UNIX and I need a sample awk or sed program to solve the following problem.

I have a file with the following format. The file is comma delimited. Each record has header information followed by looping detailed information. In addition the detailed information will vary based on a value found in the header information. For example if the header information has a value of 48 then the detail will have 48 sets of detail information. A set of detailed information is a set of 3 fields. The other value is 24, so the detail will either have 48 sets or 24 sets of detail.

What I want to do is replace the delimiter after the value 48 or 24 and around each triplete of information. I highligted the areas in bold where I want to change the comma to a semi colon.

Sample of current record:
MEPMD01,19970819,Sensus,SDGE,SDGE,,200705221435,1888961,OK,E,KWH,1,00000015,48,200705210715,R 00 40,2.0000,200705210730,R 00 40,1.0000,200705210745,R 00 40,2.0000,200705210800,R 00 40,1.0000,200705210815,R 00 40,2.0000,200705210830,R 00 40,2.0000,200705210845,R 00 40,1.0000,200705210900,R 00 40,2.0000,200705210915,R 00 40,2.0000,200705210930,R 00 40,1.0000,200705210945,R 00 40,2.0000,200705211000,R 00 40,1.0000,200705211015,R 00 40,2.0000,200705211030,R 00 40,2.0000,200705211045,R 00 40,1.0000,200705211100,R 00 40,2.0000,200705211115,R 00 40,2.0000,200705211130,R 00 40,1.0000,200705211145,R 00 40,2.0000,200705211200,R 00 40,1.0000,200705211215,R 00 40,2.0000,200705211230,R 00 40,2.0000,200705211245,R 00 40,1.0000,200705211300,R 00 40,2.0000,200705211315,R 00 40,2.0000,200705211330,R 00 40,1.0000,200705211345,R 00 40,2.0000,200705211400,R 00 40,1.0000,200705211415,R 00 40,1.0000,200705211430,R 00 40,2.0000,200705211445,R 00 40,1.0000,200705211500,R 00 40,1.0000,200705211515,R 00 40,1.0000,200705211530,R 00 40,1.0000,200705211545,R 00 40,1.0000,200705211600,R 00 40,1.0000,200705211615,R 00 40,1.0000,200705211630,R 00 40,1.0000,200705211645,R 00 40,1.0000,200705211700,R 00 40,1.0000,200705211715,R 00 40,1.0000,200705211730,R 00 40,1.0000,200705211745,R 00 40,1.0000,200705211800,R 00 40,1.0000,200705211815,R 00 40,1.0000,200705211830,R 00 40,1.0000,200705211845,R 00 40,1.0000,200705211900,R 00 40,1.0000

Roy Ayala
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-27-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,207
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Try...
Code:
awk -F, '{for(i=1;i<NF;i++) printf $i (i>13&&i%3==2?";":",");print $NF}' file1
Tested...
MEPMD01,19970819,Sensus,SDGE,SDGE,,200705221435,1888961,OK,E,KWH,1,00000015,48;200705210715,R 00 40,2.0000;200705210730,R 00 40,1.0000;200705210745,R 00 40,2.0000;200705210800,R 00 40,1.0000;200705210815,R 00 40,2.0000;200705210830,R 00 40,2.0000;200705210845,R 00 40,1.0000;200705210900,R 00 40,2.0000;200705210915,R 00 40,2.0000;200705210930,R 00 40,1.0000;200705210945,R 00 40,2.0000;200705211000,R 00 40,1.0000;200705211015,R 00 40,2.0000;200705211030,R 00 40,2.0000;200705211045,R 00 40,1.0000;200705211100,R 00 40,2.0000;200705211115,R 00 40,2.0000;200705211130,R 00 40,1.0000;200705211145,R 00 40,2.0000;200705211200,R 00 40,1.0000;200705211215,R 00 40,2.0000;200705211230,R 00 40,2.0000;200705211245,R 00 40,1.0000;200705211300,R 00 40,2.0000;200705211315,R 00 40,2.0000;200705211330,R 00 40,1.0000;200705211345,R 00 40,2.0000;200705211400,R 00 40,1.0000;200705211415,R 00 40,1.0000;200705211430,R 00 40,2.0000;200705211445,R 00 40,1.0000;200705211500,R 00 40,1.0000;200705211515,R 00 40,1.0000;200705211530,R 00 40,1.0000;200705211545,R 00 40,1.0000;200705211600,R 00 40,1.0000;200705211615,R 00 40,1.0000;200705211630,R 00 40,1.0000;200705211645,R 00 40,1.0000;200705211700,R 00 40,1.0000;200705211715,R 00 40,1.0000;200705211730,R 00 40,1.0000;200705211745,R 00 40,1.0000;200705211800,R 00 40,1.0000;200705211815,R 00 40,1.0000;200705211830,R 00 40,1.0000;200705211845,R 00 40,1.0000;200705211900,R 00 40,1.0000
Reply With Quote
  #3 (permalink)  
Old 09-28-2007
Registered User
 

Join Date: Sep 2007
Posts: 2
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
awk code

Ygor,

Fantatic, this code worked!!! I appreciate your help. Now I will try and figure out the code.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101