Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Parsing a C header file

$
0
0

Hello folks,

I have a C++ header file that I want to parse out and eventually import

into a database.

 

The header file is like this.

 

////////////////////////////////////////////////////

// Email properties250

#define    propGroupEmail250

#define    propertySmtpServer251

#define    propertySmtpPort               252

#define    propertySmtpUseAuthentication        253

#define    propertySmtpDefaultEmail254

#define  propertyValidEmailCharacters   255

#define    propertySmtpUserName256

#define    propertySmtpPassword           257

#define    propertyCharactersPerLine            258

////////////////////////////////////////////////////

// SMS properties300

#define    propGroupSMS  300

#define    propertySendSMSServer301

#define    propertySendSMSPort               302

#define    propertySendSMSUserName303

#define    propertySendSMSPassword           304

 

etc

 

I want to you use Powershell to parse this out

and give me a csv file ( which I would think should

be easy for me to import in Sql Server).

 

Here is what I am looking for as the output

 

propGroupEmail,250,250

propertySmtpServer,250,251

propertySmtpPort,       250,    252

propertySmtpUseAuthentication,  250,    253

propertySmtpDefaultEmail,250,    254

propertyValidEmailCharacters,250,255

propertySmtpUserName,250,    256

propertySmtpPassword,   250,    257

propertyCharactersPerLine,      250,    258

propGroupSMS,  300,300

propertySendSMSServer,300,301

propertySendSMSPort,       300,    302

propertySendSMSUserName,300,303

propertySendSMSPassword,   300,    304

 

(not sure why, but this was more aligned in my text editor, prior to my pasting)

I tried using the fixed width approach with select -property @{}, but that required that I 

parse out by substring and since this file is not perfectly aligned, that did not seem possible.

I then tried using the -pattern approach, but that became a bit hairy as I need to do a 'look back' to replace the "propGroup" number.

I could pre-save the "propGroup" number in a temporary variable I suppose and then use it

in a foreach...

I will need to parse this header file periodically and build new lists to import into a Database.

I just thought I would ask for any hints or approaches, or similar example

i could learn from, or I could attempt.

Thanks again for any help! 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles